From: garciadeblas Date: Thu, 18 Dec 2025 11:42:09 +0000 (+0100) Subject: Add new parameters for KSU creation/update to avoid overloading params file X-Git-Tag: v19.0.0~7 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=076f46051e7836bfab729d56a13aedb1898cb701;p=osm%2Fosmclient.git Add new parameters for KSU creation/update to avoid overloading params file Change-Id: I4770c3d424301c8c15dd90a3195ed076fda98390 Signed-off-by: garciadeblas --- diff --git a/osmclient/cli_commands/ksu.py b/osmclient/cli_commands/ksu.py index a7fcaa55..c999d2b2 100755 --- a/osmclient/cli_commands/ksu.py +++ b/osmclient/cli_commands/ksu.py @@ -25,6 +25,16 @@ import yaml 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("") @@ -110,11 +120,38 @@ def process_common_ksu_params(ctx, ksu_dict, ksu_args): 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: @@ -188,9 +225,10 @@ def process_ksu_params(ctx, param, value): --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"] """ @@ -243,7 +281,14 @@ def ksu_create(ctx, args, 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: @@ -251,9 +296,12 @@ def ksu_create(ctx, args, ksu_params): --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)}")