From 669ea1b5427eb2aee5a315da1e12a718b1a46d1c Mon Sep 17 00:00:00 2001 From: Alexandr Stefurishin Date: Tue, 10 Dec 2024 10:09:43 +0300 Subject: [PATCH 1/3] Fix access to missing finalizers, always add default finalizer during migration Signed-off-by: Alexandr Stefurishin --- hooks/convert_bd_names_to_selector.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hooks/convert_bd_names_to_selector.py b/hooks/convert_bd_names_to_selector.py index f96a0176..37a00916 100755 --- a/hooks/convert_bd_names_to_selector.py +++ b/hooks/convert_bd_names_to_selector.py @@ -248,18 +248,18 @@ def main(ctx: hook.Context): print(f"{migrate_script} starts to create backups and add 'kubernetes.io/hostname' to store the node name") for lvg in lvg_list.get('items', []): lvg_backup = {'apiVersion': lvg['apiVersion'], - 'kind': 'LvmVolumeGroupBackup', - 'metadata': { - 'name': - lvg['metadata'][ - 'name'], - 'labels': {}, - 'finalizers': - lvg['metadata'][ - 'finalizers']}, - 'spec': lvg['spec']} + 'kind': 'LvmVolumeGroupBackup', + 'metadata': { + 'name': + lvg['metadata'][ + 'name'], + 'labels': {}, + 'finalizers': lvg['metadata'].get('finalizers', [])}, + 'spec': lvg['spec']} if 'labels' in lvg['metadata']: lvg_backup['metadata']['labels'] = lvg['metadata']['labels'] + if default_finalizer not in lvg_backup['metadata']['finalizers']: + lvg_backup['metadata']['finalizers'].append('storage.deckhouse.io/sds-node-configurator') lvg_backup['metadata']['labels']['kubernetes.io/hostname'] = lvg['status']['nodes'][0]['name'] lvg_backup['metadata']['labels'][migration_completed_label] = 'false' From 5cc59a51607819f175676d8b52f02361c9f1ef8e Mon Sep 17 00:00:00 2001 From: Alexandr Stefurishin Date: Tue, 10 Dec 2024 10:32:47 +0300 Subject: [PATCH 2/3] fix formatting Signed-off-by: Alexandr Stefurishin --- hooks/convert_bd_names_to_selector.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hooks/convert_bd_names_to_selector.py b/hooks/convert_bd_names_to_selector.py index 37a00916..df04a8bd 100755 --- a/hooks/convert_bd_names_to_selector.py +++ b/hooks/convert_bd_names_to_selector.py @@ -247,15 +247,16 @@ def main(ctx: hook.Context): # we store the using node name as a label due to we will lose the status for the backup resource print(f"{migrate_script} starts to create backups and add 'kubernetes.io/hostname' to store the node name") for lvg in lvg_list.get('items', []): - lvg_backup = {'apiVersion': lvg['apiVersion'], - 'kind': 'LvmVolumeGroupBackup', - 'metadata': { - 'name': - lvg['metadata'][ - 'name'], - 'labels': {}, - 'finalizers': lvg['metadata'].get('finalizers', [])}, - 'spec': lvg['spec']} + lvg_backup = { + 'apiVersion': lvg['apiVersion'], + 'kind': 'LvmVolumeGroupBackup', + 'metadata': { + 'name': lvg['metadata']['name'], + 'labels': {}, + 'finalizers': lvg['metadata'].get('finalizers', []) + }, + 'spec': lvg['spec'] + } if 'labels' in lvg['metadata']: lvg_backup['metadata']['labels'] = lvg['metadata']['labels'] if default_finalizer not in lvg_backup['metadata']['finalizers']: From 2853af1082188faa65fee375db4ba369bd0fbfb8 Mon Sep 17 00:00:00 2001 From: Alexandr Stefurishin Date: Tue, 10 Dec 2024 10:35:19 +0300 Subject: [PATCH 3/3] fix Signed-off-by: Alexandr Stefurishin --- hooks/convert_bd_names_to_selector.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/convert_bd_names_to_selector.py b/hooks/convert_bd_names_to_selector.py index df04a8bd..cd2aa81b 100755 --- a/hooks/convert_bd_names_to_selector.py +++ b/hooks/convert_bd_names_to_selector.py @@ -259,8 +259,9 @@ def main(ctx: hook.Context): } if 'labels' in lvg['metadata']: lvg_backup['metadata']['labels'] = lvg['metadata']['labels'] + default_finalizer = 'storage.deckhouse.io/sds-node-configurator' if default_finalizer not in lvg_backup['metadata']['finalizers']: - lvg_backup['metadata']['finalizers'].append('storage.deckhouse.io/sds-node-configurator') + lvg_backup['metadata']['finalizers'].append(default_finalizer) lvg_backup['metadata']['labels']['kubernetes.io/hostname'] = lvg['status']['nodes'][0]['name'] lvg_backup['metadata']['labels'][migration_completed_label] = 'false'