diff --git a/hooks/convert_bd_names_to_selector.py b/hooks/convert_bd_names_to_selector.py index a255f8c7..5e44fc84 100755 --- a/hooks/convert_bd_names_to_selector.py +++ b/hooks/convert_bd_names_to_selector.py @@ -57,7 +57,7 @@ def main(ctx: hook.Context): try: api_v1.delete_namespaced_daemon_set(name=ds_name, namespace=ds_ns) except kubernetes.client.exceptions.ApiException as e: - if e.status == '404': + if e.status == 404: pass except Exception as e: raise e @@ -78,7 +78,8 @@ def main(ctx: hook.Context): version=version) print(f"{migrate_script} successfully listed lvmvolumegroup resources") except kubernetes.client.exceptions.ApiException as e: - if e.status == '404': + # means no lvmvolumegroup resources found + if e.status == 404: print(f"{migrate_script} no lvmvolumegroup resources found, tries to delete LvmVolumeGroup CRD") try: api_extension.delete_custom_resource_definition(crd_name) @@ -105,10 +106,10 @@ def main(ctx: hook.Context): lvg_backup['metadata']['labels']['kubernetes.io/hostname'] = lvg_backup['status']['nodes'][0]['name'] lvg_backup['metadata']['labels'][migration_completed_label] = 'false' try: - create_or_update_custom_resource(group, - 'lvmvolumegroupbackups', - version, - lvg_backup) + create_or_update_custom_resource(group=group, + plural='lvmvolumegroupbackups', + version=version, + resource=lvg_backup) except Exception as e: print(f"{migrate_script} unable to create backup, error: {e}") @@ -134,7 +135,7 @@ def main(ctx: hook.Context): try: api_extension.delete_custom_resource_definition(crd_name) except kubernetes.client.exceptions.ApiException as e: - if e.status == '404': + if e.status == 404: print(f"{migrate_script} the LvmVolumeGroup CRD has been already deleted") pass except Exception as e: @@ -160,10 +161,10 @@ def main(ctx: hook.Context): for lvg_backup in lvg_backup_list.get('items', []): lvg = configure_new_lvg(lvg_backup) try: - create_or_update_custom_resource(group, - 'lvmvolumegroups', - version, - lvg) + create_or_update_custom_resource(group=group, + plural='lvmvolumegroups', + version=version, + resource=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}") @@ -255,7 +256,7 @@ def main(ctx: hook.Context): ### End of LVMVolumeGroup CRD flow except kubernetes.client.exceptions.ApiException as e: ### If we do not find any lvmvolumegroup CRD flow - if e.status == '404': + if e.status == 404: # ничего нет, просто создаем новую CRD и создаем по бэкапам print(f"{migrate_script} no lvmvolumegroup CRD was found") @@ -379,10 +380,11 @@ def create_or_update_custom_resource(group, plural, version, resource): 'finalizers': resource['metadata'][ 'finalizers'], 'spec': resource['spec']}) - print(f"{migrate_script} {resource['kind']} {resource['metadata']['name']} created") + print(f"{migrate_script} {resource['kind']} {resource['metadata']['name']} updated") return True except kubernetes.client.exceptions.ApiException as e: - if e.status == '404': + print(f"{migrate_script} {resource['kind']} {resource['metadata']['name']} was not found, try to create it") + if e.status == 404: try: kubernetes.client.CustomObjectsApi().create_cluster_custom_object(group=group, plural=plural, @@ -401,10 +403,11 @@ def create_or_update_custom_resource(group, plural, version, resource): resource['metadata'][ 'finalizers']}, 'spec': resource['spec']}) + print(f"{migrate_script} {resource['kind']} {resource['metadata']['name']} created") except Exception as e: print( f"{migrate_script} failed to create {resource['kind']} {resource['metadata']['name']} after {max_attempts} attempts, error: {e}") - return False + return False except Exception as e: print( f"{migrate_script} attempt {attempt + 1} failed for {resource['kind']} {resource['metadata']['name']} with message: {e}") diff --git a/images/agent/src/pkg/controller/lvm_volume_group_discover.go b/images/agent/src/pkg/controller/lvm_volume_group_discover.go index 8afcd0f0..6aaac9e2 100644 --- a/images/agent/src/pkg/controller/lvm_volume_group_discover.go +++ b/images/agent/src/pkg/controller/lvm_volume_group_discover.go @@ -371,10 +371,11 @@ func ReconcileUnhealthyLVMVolumeGroups( } // take thin-pools from status instead of spec to prevent miss never-created ones - for _, thinPool := range lvg.Status.ThinPools { + for i, thinPool := range lvg.Status.ThinPools { if candidateTp, exist := candidateTPs[thinPool.Name]; !exist { log.Warning(fmt.Sprintf("[ReconcileUnhealthyLVMVolumeGroups] the LVMVolumeGroup %s misses its ThinPool %s", lvg.Name, thinPool.Name)) messageBldr.WriteString(fmt.Sprintf("Unable to find ThinPool %s. ", thinPool.Name)) + lvg.Status.ThinPools = append(lvg.Status.ThinPools[:i], lvg.Status.ThinPools[i+1:]...) } else if !utils.AreSizesEqualWithinDelta(candidate.VGSize, thinPool.ActualSize, internal.ResizeDelta) && candidateTp.ActualSize.Value()+internal.ResizeDelta.Value() < thinPool.ActualSize.Value() { // that means thin-pool is not 100%VG space @@ -980,9 +981,9 @@ func convertSpecThinPools(thinPools map[string]resource.Quantity) []v1alpha1.LVM result := make([]v1alpha1.LVMVolumeGroupThinPoolSpec, 0, len(thinPools)) for name, size := range thinPools { result = append(result, v1alpha1.LVMVolumeGroupThinPoolSpec{ - Name: name, + Name: name, AllocationLimit: "150%", - Size: size.String(), + Size: size.String(), }) }