From c2116c24ec5fbe10c6715576f2e8b56ae07ae3d1 Mon Sep 17 00:00:00 2001 From: Thibault Cohen <47721+titilambert@users.noreply.github.com> Date: Wed, 18 Jan 2023 21:12:13 -0500 Subject: [PATCH] Handle secret name/namespace edition --- src/kv.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/kv.py b/src/kv.py index 1de6c9a..409b929 100644 --- a/src/kv.py +++ b/src/kv.py @@ -64,9 +64,20 @@ def update_managed_secret(spec, status, name, namespace, logger, body, **kwargs) content_def = body['spec']['content'] id = spec.get('id') + old_config = json.loads(body.metadata.annotations['kopf.zalando.org/last-handled-configuration']) + old_secret_name = old_config['spec'].get('name') + old_secret_namespace = old_config['spec'].get('namespace') secret_name = spec.get('name') secret_namespace = spec.get('namespace') + if old_secret_name != secret_name or old_secret_namespace != secret_namespace: + # If the name of the secret or the namespace of the secret is different + # We have to delete the secret an recreate it + logger.info("Secret name or namespace changed, let's recreate it") + delete_managed_secret(old_config['spec'], name, namespace, logger, **kwargs) + create_managed_secret(spec, name, namespace, logger, body, **kwargs) + return + unlock_bw(logger) logger.info(f"Locking up secret with ID: {id}") secret_json_object = json.loads(get_secret_from_bitwarden(id))