Skip to content

Conversation

@tr-aheiev
Copy link

This PR adds a long-requested and missing feature: automatically updating all secrets when there are changes in secrets referenced by 'secretKeyRef'. A kopf decorator is used to send all secret update events to a new function called 'on_secret_update'. In this function, I parse all ClusterSecrets from the in-memory cache (it's very fast) and check whether they have a 'valueFrom' field in their data. Next, for those ClusterSecrets that have a 'valueFrom' field, I simply compare the name and namespace of the updated secret with the corresponding values in 'valueFrom'. If they match, a resync is initiated for each previously synced namespace.
It will solve 36

elif name == body['data']['valueFrom']['secretKeyRef']['name'] and namespace == body['data']['valueFrom']['secretKeyRef']['namespace']:
logger.info(f'Secret {name} in namespace {namespace}, which linked with ClusterSecret {cached_cluster_secret.name} was changed. Re-syncing')
for ns in cached_cluster_secret.synced_namespace:
sync_secret(logger, ns, body, v1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

might need to add a test in https://github.com/zakkg3/ClusterSecret/blob/master/conformance/tests.py to ensure this feature is working as expected

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for review! Yes, I plan to add test soon.

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.

2 participants