From 381a1a31c196ff179a2effed8da6afb6f9d10a50 Mon Sep 17 00:00:00 2001 From: Pablo Rodriguez Nava Date: Mon, 16 Dec 2024 17:15:03 +0100 Subject: [PATCH] [ci_gen_kustomize_values] Allow reject vars patches --- roles/ci_gen_kustomize_values/README.md | 4 ++-- .../tasks/generate_snippets.yml | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/roles/ci_gen_kustomize_values/README.md b/roles/ci_gen_kustomize_values/README.md index 4fd81bcb4f..6c23440cdf 100644 --- a/roles/ci_gen_kustomize_values/README.md +++ b/roles/ci_gen_kustomize_values/README.md @@ -35,8 +35,8 @@ with a message. * `ci_gen_kustomize_fetch_ocp_state`: (Boolean) If true it enables generating CI templates based on the OCP state. Defaults to `true`. * `cifmw_ci_gen_kustomize_values_storage_class_prefix`: (String) Prefix for `storageClass` in generated values.yaml files. Defaults to `"lvms-"` only if `cifmw_use_lvms` is True, otherwise it defaults to `""`. The prefix is prepended to the `cifmw_ci_gen_kustomize_values_storage_class`. It is not recommended to override this value, instead set `cifmw_use_lvms` True or False. * `cifmw_ci_gen_kustomize_values_storage_class`: (String) Value for `storageClass` in generated values.yaml files. Defaults to `"lvms-local-storage"` only if `cifmw_use_lvms` is True, otherwise it defaults to `"local-storage"`. -* `cifmw_ci_gen_kustomize_values_remove_keys_expressions`: (List) Remove keys matching the regular expressions from source ConfigMaps (values.yaml). - Defaults to `["^nodes$", "^node(_[0-9]+)?$"]`. +* `cifmw_ci_gen_kustomize_values_remove_keys_expressions*`: (List) Remove keys matching the regular expressions from source ConfigMaps (values.yaml). + Defaults to `["^nodes$", "^node(_[0-9]+)?$"]`. Accepts passing additional expressions by passing variables that matches `cifmw_ci_gen_kustomize_values_remove_keys_expressions.+`. ### Specific parameters for edpm-values This configMap needs some more parameters in order to properly override the `architecture` provided one. diff --git a/roles/ci_gen_kustomize_values/tasks/generate_snippets.yml b/roles/ci_gen_kustomize_values/tasks/generate_snippets.yml index fe6d535786..5c18d159d6 100644 --- a/roles/ci_gen_kustomize_values/tasks/generate_snippets.yml +++ b/roles/ci_gen_kustomize_values/tasks/generate_snippets.yml @@ -69,6 +69,15 @@ cifmw_ci_gen_kustomize_values_snippets_dir_prefix ~ _datatype) | path_join }} + _cifmw_gen_kustomize_values_reject_extra_expressions: >- + {{ + hostvars[inventory_hostname] | + dict2items | + selectattr("key", "match", "^cifmw_ci_gen_kustomize_values_remove_keys_expressions.+") | + sort(attribute='key') | + map(attribute="value") | + list + }} ansible.builtin.set_fact: values_datatype: "{{ _datatype }}" snippet_datadir: "{{ _dest_dir }}" @@ -77,11 +86,22 @@ {{ _raw_manifests | reject('equalto', _config_map_content) }} + _cifmw_gen_kustomize_values_reject_expressions: >- + {% set _final_list = [] -%} + {% for entry in (_cifmw_gen_kustomize_values_reject_extra_expressions + + cifmw_ci_gen_kustomize_values_remove_keys_expressions) -%} + {% if entry is string -%} + {% set _ = _final_list.append(entry) -%} + {% else -%} + {% set _ = _final_list.extend(entry) -%} + {% endif -%} + {% endfor -%} + {{ _final_list | unique }} _cifmw_gen_kustomize_values_base_cm_content: >- {{ _config_map_content | ansible.utils.remove_keys( - target=cifmw_ci_gen_kustomize_values_remove_keys_expressions, + target=_cifmw_gen_kustomize_values_reject_expressions, matching_parameter='regex') }} cacheable: false