Skip to content

Commit

Permalink
hook improves
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <[email protected]>
  • Loading branch information
ViktorKram committed Sep 5, 2024
1 parent edfacaa commit 3244e0c
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions hooks/convert_bd_names_to_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ def main(ctx: hook.Context):
raise e
print(f"{migrate_script} daemon set has been successfully scaled down")



# get current lvgs with old CRD (which is LvmVolumeGroup)
try:
# this list might be LvmVolumeGroups as LVMVolumeGroups
lvg_list: Any = custom_api.list_cluster_custom_object(group=group,
Expand Down Expand Up @@ -180,8 +177,12 @@ def main(ctx: hook.Context):
for manifest in yaml.safe_load_all(f):
if manifest is None:
continue
ctx.kubernetes.create_or_update(manifest)
print(f"{migrate_script} {filename} was successfully created")
try:
ctx.kubernetes.create_or_update(manifest)
print(f"{migrate_script} {filename} was successfully created")
except Exception as e:
print(f"{migrate_script} unable to create LvmVolumeGroupBackup CRD, error: {e}")
raise e
break

print(f"{migrate_script} starts to create backups and add 'kubernetes.io/hostname' to store the node name")
Expand Down Expand Up @@ -240,12 +241,22 @@ def main(ctx: hook.Context):
print(f"{migrate_script} create new LVMVolumeGroup CRs")
for lvg_backup in lvg_backup_list.get('items', []):
lvg = configure_new_lvg(backup)
ctx.kubernetes.create(lvg)
print(f"{migrate_script} LVMVolumeGroup {lvg['metadata']['name']} was created")
try:
ctx.kubernetes.create(lvg)
print(f"{migrate_script} LVMVolumeGroup {lvg['metadata']['name']} was created")
except Exception as e:
print(f"{migrate_script} unable to create LVMVolumeGroup {lvg['metadata']['name']}, error: {e}")
raise e


try:
lvg_backup['metadata']['labels'][migration_completed_label] = 'true'
ctx.kubernetes.create_or_update(lvg_backup)
print(f"{migrate_script} the LVMVolumeGroupBackup label {migration_completed_label} was updated to true")
except Exception as e:
print(f"{migrate_script} unable to update LvmVolumeGroupBackup {lvg_backup['metadata']['name']}, error: {e}")
raise e

lvg_backup['metadata']['labels'][migration_completed_label] = 'true'
ctx.kubernetes.create_or_update(lvg_backup)
print(f"{migrate_script} the LVMVolumeGroupBackup label {migration_completed_label} was updated to true")
print(f"{migrate_script} successfully created every LVMVolumeGroup CR from backup")
except Exception as e:
print(f"{migrate_script} unable to get LvmVolumeGroupBackups, error: {e}")
Expand Down Expand Up @@ -278,13 +289,22 @@ def main(ctx: hook.Context):
continue

lvg = configure_new_lvg(lvg_backup)
ctx.kubernetes.create_or_update(lvg)
print(f"{migrate_script} LVMVolumeGroup {lvg['metadata']['name']} was created")
try:
ctx.kubernetes.create_or_update(lvg)
print(f"{migrate_script} LVMVolumeGroup {lvg['metadata']['name']} was created")
except Exception as e:
print(f"{migrate_script} unable to create LVMVolumeGroup {lvg['metadata']['name']}, error: {e}")
raise e


lvg_backup['metadata']['labels'][migration_completed_label] = 'true'
ctx.kubernetes.create_or_update(lvg_backup)
print(
f"{migrate_script} updated LvmVolumeGroupBackup {lvg['metadata']['name']} migration completed to true")
try:
ctx.kubernetes.create_or_update(lvg_backup)
print( f"{migrate_script} updated LvmVolumeGroupBackup {lvg['metadata']['name']} migration completed to true")
except Exception as e:
print(f"{migrate_script} unable to update LvmVolumeGroupBackup {lvg_backup['metadata']['name']}, error: {e}")
raise e

print(f"{migrate_script} successfully created every LVMVolumeGroup CR from backup")
# turn_on_daemonset(api_v1, ds_name, ds_ns, daemonset)
return
Expand Down

0 comments on commit 3244e0c

Please sign in to comment.