Manage situations where ODU workflows fail before it is launched (empty workflow_name) 15/14715/4
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 8 Nov 2024 00:11:46 +0000 (01:11 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 8 Nov 2024 14:53:49 +0000 (15:53 +0100)
Change-Id: I63a2113eee3626b6bc018519ca324b95ada1dc73
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osm_lcm/k8s.py
osm_lcm/odu_libs/cluster_mgmt.py
osm_lcm/odu_libs/ksu.py
osm_lcm/odu_libs/oka.py
osm_lcm/odu_libs/profiles.py
osm_lcm/odu_libs/vim_mgmt.py
osm_lcm/odu_libs/workflows.py

index 744e5c0..445c3a2 100644 (file)
@@ -98,7 +98,7 @@ class ClusterLcm(GitOpsLcm):
         self.logger.info("cluster Create Enter")
         db_cluster = content["cluster"]
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "create_cluster", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -247,7 +247,7 @@ class ClusterLcm(GitOpsLcm):
         self.logger.info("cluster delete Enter")
         db_cluster = content["cluster"]
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "delete_cluster", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -358,7 +358,7 @@ class ClusterLcm(GitOpsLcm):
         self.logger.info("profile type is : {}".format(profile_type))
         self.logger.info("profile id is : {}".format(profile_id))
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "attach_profile_to_cluster", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -421,7 +421,7 @@ class ClusterLcm(GitOpsLcm):
         self.logger.info("profile type is : {}".format(profile_type))
         self.logger.info("profile id is : {}".format(profile_id))
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "detach_profile_from_cluster", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -479,7 +479,7 @@ class ClusterLcm(GitOpsLcm):
         self.logger.info("cluster register enter")
         db_cluster = content["cluster"]
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "register_cluster", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -538,7 +538,7 @@ class ClusterLcm(GitOpsLcm):
 
         self.logger.info("db_cluster is : {}".format(db_cluster))
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "deregister_cluster", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -625,7 +625,7 @@ class ClusterLcm(GitOpsLcm):
         self.logger.info("Cluster update Enter")
         db_cluster = content["cluster"]
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "update_cluster", op_id, op_params, content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -699,7 +699,7 @@ class CloudCredentialsLcm(GitOpsLcm):
 
     async def add(self, op_id, op_params, content):
         self.logger.info("Cloud Credentials create")
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "create_cloud_credentials", op_id, op_params, content
         )
 
@@ -739,7 +739,7 @@ class CloudCredentialsLcm(GitOpsLcm):
         return
 
     async def edit(self, op_id, op_params, content):
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "update_cloud_credentials", op_id, op_params, content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -770,7 +770,7 @@ class CloudCredentialsLcm(GitOpsLcm):
 
     async def remove(self, op_id, op_params, content):
         self.logger.info("Cloud Credentials delete")
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "delete_cloud_credentials", op_id, op_params, content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -805,7 +805,7 @@ class K8sAppLcm(GitOpsLcm):
     async def create(self, op_id, op_params, content):
         self.logger.info("App Create Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "create_profile", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -853,7 +853,7 @@ class K8sAppLcm(GitOpsLcm):
     async def delete(self, op_id, op_params, content):
         self.logger.info("App delete Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "delete_profile", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -914,7 +914,7 @@ class K8sResourceLcm(GitOpsLcm):
     async def create(self, op_id, op_params, content):
         self.logger.info("Resource Create Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "create_profile", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -963,7 +963,7 @@ class K8sResourceLcm(GitOpsLcm):
         self.logger.info("Resource delete Enter")
         content = self.db.get_one("k8sresource", {"_id": content["_id"]})
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "delete_profile", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1024,7 +1024,7 @@ class K8sInfraControllerLcm(GitOpsLcm):
     async def create(self, op_id, op_params, content):
         self.logger.info("Infra controller Create Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "create_profile", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1072,7 +1072,7 @@ class K8sInfraControllerLcm(GitOpsLcm):
     async def delete(self, op_id, op_params, content):
         self.logger.info("Infra controller delete Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "delete_profile", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1133,7 +1133,7 @@ class K8sInfraConfigLcm(GitOpsLcm):
     async def create(self, op_id, op_params, content):
         self.logger.info("Infra config Create Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "create_profile", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1181,7 +1181,7 @@ class K8sInfraConfigLcm(GitOpsLcm):
     async def delete(self, op_id, op_params, content):
         self.logger.info("Infra config delete Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "delete_profile", op_id, op_params, content
         )
         self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1244,7 +1244,7 @@ class OkaLcm(GitOpsLcm):
         self.logger.info("OKA Create Enter")
         db_content = content
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "create_oka", op_id, op_params, db_content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1295,7 +1295,7 @@ class OkaLcm(GitOpsLcm):
         self.logger.info("OKA Edit Enter")
         db_content = content
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "update_oka", op_id, op_params, content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1343,7 +1343,7 @@ class OkaLcm(GitOpsLcm):
         self.logger.info("OKA delete Enter")
         db_content = content
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "delete_oka", op_id, op_params, content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1406,7 +1406,7 @@ class KsuLcm(GitOpsLcm):
     async def create(self, op_id, op_params, content):
         self.logger.info("ksu Create Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "create_ksus", op_id, op_params, content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1466,7 +1466,7 @@ class KsuLcm(GitOpsLcm):
     async def edit(self, op_id, op_params, content):
         self.logger.info("ksu edit Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "update_ksus", op_id, op_params, content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1531,7 +1531,7 @@ class KsuLcm(GitOpsLcm):
     async def delete(self, op_id, op_params, content):
         self.logger.info("ksu delete Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "delete_ksus", op_id, op_params, content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1585,7 +1585,7 @@ class KsuLcm(GitOpsLcm):
     async def clone(self, op_id, op_params, db_content):
         self.logger.info("ksu clone Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "clone_ksus", op_id, op_params, db_content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1631,7 +1631,7 @@ class KsuLcm(GitOpsLcm):
     async def move(self, op_id, op_params, db_content):
         self.logger.info("ksu move Enter")
 
-        workflow_name = await self.odu.launch_workflow(
+        _, workflow_name = await self.odu.launch_workflow(
             "move_ksus", op_id, op_params, db_content
         )
         workflow_status, workflow_msg = await self.odu.check_workflow_status(
index 81d85ec..4c24b96 100644 (file)
@@ -62,12 +62,16 @@ async def create_cluster(self, op_id, op_params, content):
     secret_namespace = "osm-workflows"
     secret_key = "agekey"
     secret_value = private_key_new_cluster
-    await self.create_secret(
-        secret_name,
-        secret_namespace,
-        secret_key,
-        secret_value,
-    )
+    try:
+        await self.create_secret(
+            secret_name,
+            secret_namespace,
+            secret_key,
+            secret_value,
+        )
+    except Exception as e:
+        self.logger.info(f"Cannot create secret {secret_name}: {e}")
+        return False, ""
 
     # Additional params for the workflow
     cluster_kustomization_name = cluster_name
@@ -131,7 +135,7 @@ async def create_cluster(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def update_cluster(self, op_id, op_params, content):
@@ -156,12 +160,16 @@ async def update_cluster(self, op_id, op_params, content):
     secret_namespace = "osm-workflows"
     secret_key = "agekey"
     secret_value = private_key_cluster
-    await self.create_secret(
-        secret_name,
-        secret_namespace,
-        secret_key,
-        secret_value,
-    )
+    try:
+        await self.create_secret(
+            secret_name,
+            secret_namespace,
+            secret_key,
+            secret_value,
+        )
+    except Exception as e:
+        self.logger.info(f"Cannot create secret {secret_name}: {e}")
+        return False, ""
 
     # Additional params for the workflow
     cluster_kustomization_name = cluster_name
@@ -213,7 +221,7 @@ async def update_cluster(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def delete_cluster(self, op_id, op_params, content):
@@ -254,7 +262,7 @@ async def delete_cluster(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def register_cluster(self, op_id, op_params, content):
@@ -277,12 +285,18 @@ async def register_cluster(self, op_id, op_params, content):
     secret_namespace = "osm-workflows"
     secret_key = "agekey"
     secret_value = private_key_new_cluster
-    await self.create_secret(
-        secret_name,
-        secret_namespace,
-        secret_key,
-        secret_value,
-    )
+    try:
+        await self.create_secret(
+            secret_name,
+            secret_namespace,
+            secret_key,
+            secret_value,
+        )
+    except Exception as e:
+        self.logger.info(
+            f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}"
+        )
+        return False, ""
 
     # Create secret with kubeconfig
     secret_name2 = f"kubeconfig-{cluster_name}"
@@ -327,7 +341,7 @@ async def register_cluster(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def deregister_cluster(self, op_id, op_params, content):
@@ -367,7 +381,7 @@ async def deregister_cluster(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def get_cluster_credentials(self, db_cluster):
index 188da8f..7f4d699 100644 (file)
@@ -163,7 +163,7 @@ async def create_ksus(self, op_id, op_params_list, content_list):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def update_ksus(self, op_id, op_params_list, content_list):
@@ -300,7 +300,7 @@ async def update_ksus(self, op_id, op_params_list, content_list):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def delete_ksus(self, op_id, op_params_list, content_list):
@@ -346,21 +346,21 @@ async def delete_ksus(self, op_id, op_params_list, content_list):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def clone_ksu(self, op_id, op_params, content):
     self.logger.info(f"clone_ksu Enter. Operation {op_id}. Params: {op_params}")
     # self.logger.debug(f"Content: {content}")
     workflow_name = f"clone-ksu-{content['_id']}"
-    return workflow_name
+    return True, workflow_name
 
 
 async def move_ksu(self, op_id, op_params, content):
     self.logger.info(f"move_ksu Enter. Operation {op_id}. Params: {op_params}")
     # self.logger.debug(f"Content: {content}")
     workflow_name = f"move-ksu-{content['_id']}"
-    return workflow_name
+    return True, workflow_name
 
 
 async def clean_items_ksu_create(self, op_id, op_params_list, content_list):
index c9205ed..62207a3 100644 (file)
@@ -75,7 +75,7 @@ async def create_oka(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def update_oka(self, op_id, op_params, content):
@@ -131,7 +131,7 @@ async def update_oka(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def delete_oka(self, op_id, op_params, content):
@@ -169,4 +169,4 @@ async def delete_oka(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
index 323250e..782d056 100644 (file)
@@ -54,7 +54,7 @@ async def create_profile(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def delete_profile(self, op_id, op_params, content):
@@ -92,7 +92,7 @@ async def delete_profile(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def attach_profile_to_cluster(self, op_id, op_params, content):
@@ -136,7 +136,7 @@ async def attach_profile_to_cluster(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def detach_profile_from_cluster(self, op_id, op_params, content):
@@ -181,4 +181,4 @@ async def detach_profile_from_cluster(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
index edb16ab..5569f89 100644 (file)
@@ -93,7 +93,7 @@ async def create_cloud_credentials(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def delete_cloud_credentials(self, op_id, op_params, content):
@@ -136,7 +136,7 @@ async def delete_cloud_credentials(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def update_cloud_credentials(self, op_id, op_params, content):
@@ -207,7 +207,7 @@ async def update_cloud_credentials(self, op_id, op_params, content):
         api_plural="workflows",
         api_version="v1alpha1",
     )
-    return workflow_name
+    return True, workflow_name
 
 
 async def clean_items_cloud_credentials_create(self, op_id, op_params, content):
index f3b9295..094aa9e 100644 (file)
@@ -23,6 +23,8 @@ from math import ceil
 
 async def check_workflow_status(self, workflow_name):
     self.logger.info(f"check_workflow_status Enter: {workflow_name}")
+    if not workflow_name:
+        return False, "Workflow was not launched"
     try:
         return await self.readiness_loop(
             item="workflow",