logger = logging.getLogger("osmclient")
+def merge_dict(d1, d2):
+ """Merges two dictionaries recursively"""
+ for k, v in d2.items():
+ if k in d1 and isinstance(d1[k], dict) and isinstance(v, dict):
+ merge_dict(d1[k], v)
+ else:
+ d1[k] = v
+ return d1
+
+
def verify_and_update_ksu(ctx, ksu):
def get_oka_id(ctx, oka_name):
logger.debug("")
oka_dict["sw_catalog_path"] = oka_args[i + 1]
i = i + 2
continue
- elif oka_args[i] == "--params":
+ elif oka_args[i] == "--namespace":
+ if (i + 1 >= len(oka_args)) or oka_args[i + 1].startswith("--"):
+ raise ClientException("No namespace was provided after --namespace")
+ oka_dict["transformation"] = oka_dict.get("transformation", {})
+ oka_dict["transformation"]["namespace"] = oka_args[i + 1]
+ i = i + 2
+ continue
+ elif oka_args[i] in (
+ "--params",
+ "--inline-values",
+ "--custom-env-vars",
+ "--secret-params",
+ "--clear-params",
+ ):
if (i + 1 >= len(oka_args)) or oka_args[i + 1].startswith("--"):
- raise ClientException("No params file was provided after --params")
+ raise ClientException("No file was provided after " + oka_args[i])
+ new_t = {}
with open(oka_args[i + 1], "r") as pf:
- oka_dict["transformation"] = yaml.safe_load(pf.read())
+ transformation_content = yaml.safe_load(pf.read())
+ if oka_args[i] == "--params":
+ new_t = transformation_content
+ elif oka_args[i] == "--inline-values":
+ new_t = {"inline_values": transformation_content}
+ elif oka_args[i] == "--custom-env-vars":
+ new_t = {"custom_env_vars": transformation_content}
+ elif oka_args[i] == "--secret-params":
+ new_t = {"secret_values": transformation_content}
+ elif oka_args[i] == "--clear-params":
+ new_t = {"configmap_values": transformation_content}
+ old_t = oka_dict.get("transformation", {})
+ transformation = merge_dict(old_t, new_t)
+ oka_dict["transformation"] = transformation
i = i + 2
continue
else:
--profile profile1 --profile-type infra-controller-profile
--oka jenkins-controller --params jenkins-controller.yaml
--oka jenkins-config --params jenkins-config.yaml
- --ksu prometheus --description "Prometheus KSU"
- --profile profile2 --profile-type infra-controller-profile
- --sw-catalog-path infra-controllers/prometheus --params prometheus-controller.yaml
+ --inline-values jenkins-values.yaml
+ --custom-env-vars jenkins-vars.yaml
+ --secret-params jenkins-secrets.yaml
+ --clear-params jenkins-clear-params.yaml
It returns the dictionary with all the params stored in ctx.params["ksu_params"]
"""
(either --oka or --sw-catalog-path must be used)
--sw-catalog-path TEXT folder in the SW catalog (git repo) that will be incorporated to the KSU
(either --oka or --sw-catalog-path must be used)
- --params FILE file with the values that parametrize the OKA or the template in SW catalog path
+ (e.g.: infra-controllers/prometheus/templates)
+ --params FILE file with the values that parametrize the kustomization asociated to the OKA
+ or the template in SW catalog path
+ --namespace TEXT namespace where the KSU will be deployed (if not provided, default namespace will be used)
+ --inline-values FILE file with inline values to be applied to the KSU
+ --custom-env-vars FILE file with custom environment variables to be applied to the KSU
+ --secret-params FILE file with secret parameters to be applied to the KSU
+ --clear-params FILE file with clear parameters to be applied to the KSU
\b
Example:
--profile profile1 --profile-type infra-controller-profile
--oka jenkins-controller --params jenkins-controller.yaml
--oka jenkins-config --params jenkins-config.yaml
- --ksu prometheus --description "Prometheus KSU"
- --profile profile2 --profile-type infra-controller-profile
- --sw-catalog-path infra-controllers/prometheus --params prometheus-controller.yaml
+ --namespace jenkins
+ --inline-values jenkins-values.yaml
+ --custom-env-vars jenkins-vars.yaml
+ --secret-params jenkins-secrets.yaml
+ --clear-params jenkins-clear-params.yaml
+
"""
logger.debug("")
logger.debug(f"ksu_params:\n{yaml.safe_dump(ksu_params)}")