Support KSUs based on kubernetes manifests and env var substitution

Change-Id: I03be2333fee7e4d0973130db504d8f3687763c51
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/osm_lcm/odu_libs/ksu.py b/osm_lcm/odu_libs/ksu.py
index 767e30b..453b43f 100644
--- a/osm_lcm/odu_libs/ksu.py
+++ b/osm_lcm/odu_libs/ksu.py
@@ -64,15 +64,22 @@
     profile_name = ksu_params.get("profile", {}).get("name")
     age_public_key = ksu_params.get("profile", {}).get("age_pubkey")
     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 = '""'
+    substitute_environment = oka_params.get("substitute_environment", "true").lower()
+    custom_env_vars = oka_params.get("custom_env_vars", {})
+    if "APPNAME" not in custom_env_vars:
+        custom_env_vars["APPNAME"] = ksu_name
+    if "TARGET_NS" not in custom_env_vars:
+        custom_env_vars["TARGET_NS"] = target_ns
+    custom_env_vars_str = "|\n"
+    substitution_filter_list = []
+    for k, v in custom_env_vars.items():
+        custom_env_vars_str += " " * 10 + f"{k}={v}\n"
+        substitution_filter_list.append(f"${k}")
+    substitution_filter = ",".join(substitution_filter_list)
+    # TODO: add additional substitution filters
+    # substitution_filter = (
+    #     f"{substitution_filter},{oka_params.get('substitution_filter', '')}".strip(",")
+    # )
     inline_values = oka_params.get("inline_values", "")
     if inline_values:
         yaml_string = yaml.safe_dump(
@@ -133,7 +140,7 @@
         templates_path=oka_path,
         substitute_environment=substitute_environment,
         substitution_filter=substitution_filter,
-        custom_env_vars=custom_env_vars,
+        custom_env_vars=custom_env_vars_str,
         kustomization_name=kustomization_name,
         helmrelease_name=helmrelease_name,
         inline_values=inline_values,
@@ -205,15 +212,22 @@
     profile_name = ksu_params.get("profile", {}).get("name")
     age_public_key = ksu_params.get("profile", {}).get("age_pubkey")
     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 = '""'
+    substitute_environment = oka_params.get("substitute_environment", "true").lower()
+    custom_env_vars = oka_params.get("custom_env_vars", {})
+    if "APPNAME" not in custom_env_vars:
+        custom_env_vars["APPNAME"] = ksu_name
+    if "TARGET_NS" not in custom_env_vars:
+        custom_env_vars["TARGET_NS"] = target_ns
+    custom_env_vars_str = "|\n"
+    substitution_filter_list = []
+    for k, v in custom_env_vars.items():
+        custom_env_vars_str += " " * 10 + f"{k}={v}\n"
+        substitution_filter_list.append(f"${k}")
+    substitution_filter = ",".join(substitution_filter_list)
+    # TODO: add additional substitution filters
+    # substitution_filter = (
+    #     f"{substitution_filter},{oka_params.get('substitution_filter', '')}".strip(",")
+    # )
     inline_values = oka_params.get("inline_values", "")
     if inline_values:
         yaml_string = yaml.safe_dump(
@@ -273,7 +287,7 @@
         templates_path=oka_path,
         substitute_environment=substitute_environment,
         substitution_filter=substitution_filter,
-        custom_env_vars=custom_env_vars,
+        custom_env_vars=custom_env_vars_str,
         kustomization_name=kustomization_name,
         helmrelease_name=helmrelease_name,
         inline_values=inline_values,