Skip to content

Commit 8ecd704

Browse files
committed
hook improves
Signed-off-by: Viktor Kramarenko <[email protected]>
1 parent b6ecaef commit 8ecd704

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

hooks/convert_bd_names_to_selector.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# limitations under the License.
1616
import copy
1717
import os
18-
import time
1918
from typing import Any, List
2019

2120
import yaml
@@ -71,12 +70,11 @@ def main(ctx: hook.Context):
7170
# so we might have LvmVolumeGroup list or LVMVolumeGroup list
7271
if len(lvg_list.get('items', [])) == 0:
7372
try:
74-
# ctx.kubernetes.delete(kind='CustomResourceDefinition',
75-
# apiVersion='apiextensions.k8s.io/v1',
76-
# name='LvmVolumeGroup',
77-
# namespace='')
73+
ctx.kubernetes.delete(kind='CustomResourceDefinition',
74+
apiVersion='apiextensions.k8s.io/v1',
75+
name='LvmVolumeGroup',
76+
namespace='')
7877

79-
api_extenstion.delete_custom_resource_definition('lvmvolumegroups.storage.deckhouse.io')
8078
print(f"{migrate_script} successfully delete the LvmVolumeGroup CRD")
8179
# that means we deleted old kind (LvmVolumeGroup)
8280
create_new_lvg_crd(ctx)
@@ -90,8 +88,7 @@ def main(ctx: hook.Context):
9088
version=version)
9189
for backup in lvg_backup_list.get('items', []):
9290
if backup['metadata']['labels'][migration_completed_label] == 'true':
93-
print(
94-
f"{migrate_script} the LvmVolumeGroup {backup['metadata']['name']} was already migrated")
91+
print(f"{migrate_script} the LvmVolumeGroup {backup['metadata']['name']} was already migrated")
9592
continue
9693

9794
lvg = configure_new_lvg(backup)
@@ -316,8 +313,12 @@ def configure_new_lvg(backup):
316313

317314
def turn_on_daemonset(api_v1, name, namespace, daemonset):
318315
del daemonset['spec']['template']['spec']['nodeSelector']['exclude']
319-
print(f"{migrate_script} successfully migrated LvmVolumeGroup kind to LVMVolumeGroup")
320-
api_v1.patch_namespaced_daemon_set(name=name, namespace=namespace, body=daemonset)
316+
try:
317+
api_v1.patch_namespaced_daemon_set(name=name, namespace=namespace, body=daemonset)
318+
print(f"{migrate_script} successfully migrated LvmVolumeGroup kind to LVMVolumeGroup")
319+
except Exception as e:
320+
print(f"{migrate_script} an ERROR occurred while turning on the daemonset, err: {e}")
321+
321322

322323

323324
def find_crds_root(hookpath):

0 commit comments

Comments
 (0)