Fix parsing of OKA params in KSU creation and update workflows 40/14640/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 16 Oct 2024 09:43:36 +0000 (11:43 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 16 Oct 2024 09:43:36 +0000 (11:43 +0200)
Change-Id: If12563f80f23df6305249a09df27fa1e8cd23b04
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osm_lcm/odu_libs/ksu.py

index 0326264..0292434 100644 (file)
@@ -43,6 +43,7 @@ async def create_ksus(self, op_id, op_params_list, content_list):
             "There is no ODU workflow yet able to manage multiple OKAs for a KSU"
         )
     oka_item = oka_list[0]
+    oka_params = oka_item.get("transformation", {})
     if "sw_catalog_path" in oka_item:
         oka_path = oka_item["sw_catalog_path"]
     else:
@@ -58,21 +59,21 @@ async def create_ksus(self, op_id, op_params_list, content_list):
     osm_project_name = "osm_admin"  # TODO: get project name from db_ksu
     kustomization_name = ksu_name
     helmrelease_name = ksu_name
-    target_ns = ksu_params.get("namespace", "default")
     profile_type = ksu_params.get("profile", {}).get("profile_type")
     profile_type = MAP_PROFILE[profile_type]
     profile_name = ksu_params.get("profile", {}).get("name")
     age_public_key = ksu_params.get("profile", {}).get("age_pubkey")
-    substitute_environment = ksu_params.get("substitute_environment", "false")
-    substitution_filter = ksu_params.get("substitution_filter", "")
-    custom_env_vars = ksu_params.get("custom_env_vars", "")
+    target_ns = oka_params.get("namespace", "default")
+    substitute_environment = oka_params.get("substitute_environment", "false")
+    substitution_filter = oka_params.get("substitution_filter", "")
+    custom_env_vars = oka_params.get("custom_env_vars", "")
     if custom_env_vars:
         custom_env_vars = "|\n" + "\n".join(
             [" " * 10 + f"{k}={v}" for k, v in custom_env_vars.items()]
         )
     else:
         custom_env_vars = '""'
-    inline_values = ksu_params.get("inline_values", "")
+    inline_values = oka_params.get("inline_values", "")
     if inline_values:
         yaml_string = yaml.safe_dump(
             inline_values, sort_keys=False, default_flow_style=False
@@ -83,7 +84,7 @@ async def create_ksus(self, op_id, op_params_list, content_list):
     else:
         inline_values = '""'
     is_preexisting_cm = "false"
-    cm_values = ksu_params.get("configmap_values", "")
+    cm_values = oka_params.get("configmap_values", "")
     if cm_values:
         yaml_string = yaml.safe_dump(
             cm_values, sort_keys=False, default_flow_style=False
@@ -98,7 +99,7 @@ async def create_ksus(self, op_id, op_params_list, content_list):
         cm_key = ""
         cm_values = '""'
     is_preexisting_secret = "false"
-    secret_values = ksu_params.get("secret_values", "")
+    secret_values = oka_params.get("secret_values", "")
     if secret_values:
         values_secret_name = f"secret-{ksu_name}"
         reference_secret_for_values = f"ref-secret-{ksu_name}"
@@ -182,7 +183,14 @@ async def update_ksus(self, op_id, op_params_list, content_list):
         raise Exception(
             "There is no ODU workflow yet able to manage multiple OKAs for a KSU"
         )
-    oka_path = oka_list[0]["sw_catalog_path"]
+    oka_item = oka_list[0]
+    oka_params = oka_item.get("transformation", {})
+    if "sw_catalog_path" in oka_item:
+        oka_path = oka_item["sw_catalog_path"]
+    else:
+        oka_type = "infra-controllers"
+        oka_name = oka_item["git_name"]
+        oka_path = f"{oka_type}/{oka_name}/templates"
 
     workflow_template = "launcher-update-ksu-hr.j2"
     workflow_name = f"update-ksus-{op_id}"
@@ -192,21 +200,21 @@ async def update_ksus(self, op_id, op_params_list, content_list):
     osm_project_name = "osm_admin"  # TODO: get project name from db_ksu
     kustomization_name = ksu_name
     helmrelease_name = ksu_name
-    target_ns = ksu_params.get("namespace", "default")
     profile_type = ksu_params.get("profile", {}).get("profile_type")
     profile_type = MAP_PROFILE[profile_type]
     profile_name = ksu_params.get("profile", {}).get("name")
     age_public_key = ksu_params.get("profile", {}).get("age_pubkey")
-    substitute_environment = ksu_params.get("substitute_environment", "false")
-    substitution_filter = ksu_params.get("substitution_filter", "")
-    custom_env_vars = ksu_params.get("custom_env_vars", "")
+    target_ns = oka_params.get("namespace", "default")
+    substitute_environment = oka_params.get("substitute_environment", "false")
+    substitution_filter = oka_params.get("substitution_filter", "")
+    custom_env_vars = oka_params.get("custom_env_vars", "")
     if custom_env_vars:
         custom_env_vars = "|\n" + "\n".join(
             [" " * 10 + f"{k}={v}" for k, v in custom_env_vars.items()]
         )
     else:
         custom_env_vars = '""'
-    inline_values = ksu_params.get("inline_values", "")
+    inline_values = oka_params.get("inline_values", "")
     if inline_values:
         yaml_string = yaml.safe_dump(
             inline_values, sort_keys=False, default_flow_style=False
@@ -217,7 +225,7 @@ async def update_ksus(self, op_id, op_params_list, content_list):
     else:
         inline_values = '""'
     is_preexisting_cm = "false"
-    cm_values = ksu_params.get("configmap_values", "")
+    cm_values = oka_params.get("configmap_values", "")
     if cm_values:
         yaml_string = yaml.safe_dump(
             cm_values, sort_keys=False, default_flow_style=False
@@ -232,7 +240,7 @@ async def update_ksus(self, op_id, op_params_list, content_list):
         cm_key = ""
         cm_values = '""'
     is_preexisting_secret = "false"
-    secret_values = ksu_params.get("secret_values", "")
+    secret_values = oka_params.get("secret_values", "")
     if secret_values:
         values_secret_name = f"secret-{ksu_name}"
         reference_secret_for_values = f"ref-secret-{ksu_name}"