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

Improvement. Automatic synchronization of changes from 'linked' secrets #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ async def namespace_watcher(logger: logging.Logger, meta: kopf.Meta, **_):
custom_objects_api=custom_objects_api,
)

@kopf.on.update('', 'v1', 'secrets')
async def on_secret_update(logger: logging.Logger, name: str, namespace: str, **_):
"""Watch for secret update events
"""
for cached_cluster_secret in csecs_cache.all_cluster_secret():
body = cached_cluster_secret.body

if 'valueFrom' not in body['data']:
continue
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.


@kopf.on.startup()
async def startup_fn(logger: logging.Logger, **_):
Expand Down
Loading