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-3587] Old secret field translations (issue #140) #141

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

juditnovak
Copy link
Contributor

@juditnovak juditnovak commented Feb 16, 2024

Problem

This PR is targeting the issue where we have to use different secret fields than what we had in the databag.

Typically ca (short) or auth_cfg (_ not permitted) are currently "manyally" translated on the charm's side.

The difference between old/new names typically causes an issue for rolling upgrades. Currently PG charms and soon upcoming Zookeeper would be impacted by this issue.

After a LOT of thinking, the lib seemed to be the right place to hold this logic, as it's already handling the rest of the backwards compatibility functionalities (typically for rolling upgrades). The current code is already following through changes like moving sensitive data from databag to secrets, or to move from a secret URI (stored in databag) to secret labels. Since the translation problem is strongly related to the former, the logic should go to the lib. Even though I'm not happy about this extra complexity at all :-/

Implementation

I chose to take a mapping as a parameter, as this should cover existing use-cases. The other option would have been to add a user-defined translation function, however that feels a lot less safe (i.e. introducting bugs on secrets!!!) than a straightforward mapping. Note that the current scheme is easily extendible to take both options.

POC (Pgbouncer)

The POC of this working with Pgbouncer (one of the main requestors of the feature) can be found here: canonical/pgbouncer-operator#149

Let me know what you think.

@juditnovak juditnovak force-pushed the DPE-3587_old_secret_field_translations branch 2 times, most recently from 238018b to 05bde73 Compare February 16, 2024 13:13
@juditnovak juditnovak force-pushed the DPE-3587_old_secret_field_translations branch from 05bde73 to ba1c965 Compare February 16, 2024 13:16
@juditnovak juditnovak changed the title [DPE-3587] Old secret field translations [DPE-3587] Old secret field translations (issue #140) Feb 16, 2024
return self._fetch_relation_data_with_secrets(
self.component, self.secret_fields, relation, fields
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is not needed for DataPeer, cleaning it up

secret_fields_passed = set(self.secret_fields) & set(fields)
for field in secret_fields_passed:
if self._fetch_relation_data_without_secrets(self.component, relation, [field]):
self._delete_relation_data_without_secrets(self.component, relation, [field])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The above function got "re-grouped" to the suited block, with mild modifications

logger.error(
"Non-existing secret %s was attempted to be removed.",
", ".join(non_existent),
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The checks above are now moved to aonther 'backwards compatiblity' (bc) function

self._secrets.pop(label)
else:
logging.error("Non-existing Juju Secret was attempted to be removed %s", label)


Copy link
Contributor Author

Choose a reason for hiding this comment

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

The two changes above are a small but important bugfix. Used at secret deletion below.

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

Successfully merging this pull request may close these issues.

1 participant