Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPE-2442] Add juju secrets support #242

Merged
merged 23 commits into from
Sep 15, 2023
Merged

Conversation

dmitry-ratushnyy
Copy link
Contributor

@dmitry-ratushnyy dmitry-ratushnyy commented Sep 1, 2023

Issue

Add support of juju secrets to the charm

Related issues

DPE-2441
DPE-2442
DPE-2443

@dmitry-ratushnyy dmitry-ratushnyy force-pushed the dmitry.ratushnyy/DPE-2442_fix branch 3 times, most recently from 4ef75ad to b604378 Compare September 2, 2023 19:34
@dmitry-ratushnyy dmitry-ratushnyy changed the base branch from dratushnyy/DPE-2442 to main September 4, 2023 06:09
@dmitry-ratushnyy dmitry-ratushnyy changed the title WIP: Fixing issue with charm [DPE-2442] Add juju secrets support Sep 4, 2023
Copy link
Contributor

@MiaAltieri MiaAltieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly nits :)

lib/charms/mongodb/v0/mongodb_tls.py Outdated Show resolved Hide resolved
lib/charms/mongodb/v0/mongodb_tls.py Outdated Show resolved Hide resolved
lib/charms/mongodb/v0/mongodb_tls.py Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Show resolved Hide resolved
tests/integration/helpers.py Outdated Show resolved Hide resolved
tests/integration/test_charm.py Outdated Show resolved Hide resolved
tests/integration/test_charm.py Show resolved Hide resolved
src/config.py Outdated Show resolved Hide resolved
tests/integration/backup_tests/test_backups.py Outdated Show resolved Hide resolved
tests/integration/ha_tests/helpers.py Outdated Show resolved Hide resolved
tests/unit/test_charm.py Show resolved Hide resolved
"""Helper function to get Juju secret."""
peer_data = self._peer_data(scope)

if not peer_data.get(Config.Secrets.SECRET_INTERNAL_LABEL):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peer data bag stores the Secret ID inside in SECRET_INTERNAL_LABEL field.
The current code cannot retrieve the Secret object if we don't have the Secret ID (line 1126 below).
I think this part is going to be revoked in two weeks.

src/charm.py Outdated
return self.secrets[scope][Config.Secrets.SECRET_LABEL].id

def _juju_secrets_get(self, scope: Scopes) -> Optional[bool]:
"""Helper function to get Juju secret."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function name can be better. in fact, it is just caching secret content into the internal dictionary.

Copy link
Contributor

@juditnovak juditnovak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests should be consistent relying on the juju_has_secrets autoreused fixture.

tests/integration/tls_tests/helpers.py Outdated Show resolved Hide resolved
tox.ini Show resolved Hide resolved
MiaAltieri
MiaAltieri previously approved these changes Sep 4, 2023
Copy link
Contributor

@MiaAltieri MiaAltieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

delgod
delgod previously approved these changes Sep 5, 2023
tests/unit/test_charm.py Show resolved Hide resolved
MiaAltieri added a commit that referenced this pull request Sep 6, 2023
## Problem 
After implementing backups on K8s the libraries in each charm are out of
sync.

## Solution
Update the library code and update the charm to support these new
changes

## Other changes
Testing versions and requirements updates to solve depency issues in
tests

## Future PRs
The backup library has had substantial changes and so the old test suite
is no longer supported. In a future PR these will be added.
Failing TLS tests are resolved in #242 

## do NOT review these files
- `lib/charms/mongodb/v0/helpers.py` - copy and paste from k8s charm
- `lib/charms/mongodb/v0/mongodb_backups.py` - copy and paste from VM
charm
- `tests/unit/test_mongodb_backups.py` - removed as is now out of date,
will be rewritten in a follow up PR
@dmitry-ratushnyy dmitry-ratushnyy force-pushed the dmitry.ratushnyy/DPE-2442_fix branch 4 times, most recently from 377ec57 to e4200f1 Compare September 8, 2023 06:16
@dmitry-ratushnyy dmitry-ratushnyy force-pushed the dmitry.ratushnyy/DPE-2442_fix branch from 688f0e5 to ea883c5 Compare September 13, 2023 12:21
delgod
delgod previously approved these changes Sep 13, 2023
MiaAltieri
MiaAltieri previously approved these changes Sep 14, 2023
Copy link
Contributor

@MiaAltieri MiaAltieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work Dmitry :)

src/charm.py Show resolved Hide resolved
src/charm.py Show resolved Hide resolved
src/charm.py Outdated
return self.secrets[scope][Config.Secrets.SECRET_LABEL].id

def _juju_secrets_get(self, scope: Scopes) -> Optional[bool]:
"""Helper function to get Juju secret."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like Judits docstring here, I think it explains the complexities that are going on. Unless you feel strongly about removing it.

tests/integration/test_charm.py Show resolved Hide resolved
src/charm.py Show resolved Hide resolved
src/charm.py Outdated
return self.secrets[scope][Config.Secrets.SECRET_LABEL].id

def _juju_secrets_get(self, scope: Scopes) -> Optional[bool]:
"""Helper function to get Juju secret."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with myself and @MiaAltieri :-D

Could we pls use the more verbose (and actually correct 😅 ) docstring here?
I apologize for the original one, it's on me, I'll update it in k8s as well

src/charm.py Show resolved Hide resolved
src/config.py Show resolved Hide resolved
tests/conftest.py Show resolved Hide resolved
tests/integration/test_charm.py Show resolved Hide resolved
tests/integration/test_charm.py Show resolved Hide resolved
Co-authored-by: Mia Altieri <[email protected]>
@dmitry-ratushnyy dmitry-ratushnyy dismissed stale reviews from MiaAltieri and delgod via 45456f1 September 14, 2023 13:56
juditnovak
juditnovak previously approved these changes Sep 14, 2023
Copy link
Contributor

@juditnovak juditnovak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


secret_cache[key] = Config.Secrets.SECRET_DELETED_LABEL
secret.set_content(secret_cache)
logging.debug(f"Secret {scope}:{key}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we or improve the message here or remove it?

Suggested change
logging.debug(f"Secret {scope}:{key}")
logging.debug(f"Secret {scope}:{key} removed")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants