From dbcff999e6c656482ce5b84d071dc2b2c114f90b Mon Sep 17 00:00:00 2001 From: John Mazzitelli Date: Mon, 11 Jul 2022 09:45:25 -0400 Subject: [PATCH] refactor large blob of code that converts yaml from snake case to camel case extract to a separate file to make it easier to maintain --- roles/default/kiali-deploy/tasks/main.yml | 162 +----------------- .../kiali-deploy/tasks/snake_camel_case.yaml | 160 +++++++++++++++++ 2 files changed, 162 insertions(+), 160 deletions(-) create mode 100644 roles/default/kiali-deploy/tasks/snake_camel_case.yaml diff --git a/roles/default/kiali-deploy/tasks/main.yml b/roles/default/kiali-deploy/tasks/main.yml index 75bf11b1..1002f5bf 100644 --- a/roles/default/kiali-deploy/tasks/main.yml +++ b/roles/default/kiali-deploy/tasks/main.yml @@ -90,166 +90,8 @@ - kiali_vars.deployment.ingress_enabled is defined - kiali_vars.deployment.ingress is not defined or kiali_vars.deployment.ingress.enabled is not defined -# Because we are passing through some yaml directly to Kubernetes resources, we have to retain the camelCase keys. -# All CR parameters are converted to snake_case, but the original yaml is found in the special _kiali_io_kiali param. -# We need to copy that original yaml into our vars where appropriate to keep the camelCase. - -- name: Replace snake_case with camelCase in deployment.affinity.node - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment']['affinity'].pop('node') %} - {{ kiali_vars | combine({'deployment': {'affinity': {'node': current_cr.spec.deployment.affinity.node }}}, recursive=True) }} - when: - - kiali_vars.deployment.affinity is defined - - kiali_vars.deployment.affinity.node is defined - - kiali_vars.deployment.affinity.node | length > 0 - -- name: Replace snake_case with camelCase in deployment.affinity.pod - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment']['affinity'].pop('pod') %} - {{ kiali_vars | combine({'deployment': {'affinity': {'pod': current_cr.spec.deployment.affinity.pod }}}, recursive=True) }} - when: - - kiali_vars.deployment.affinity is defined - - kiali_vars.deployment.affinity.pod is defined - - kiali_vars.deployment.affinity.pod | length > 0 - -- name: Replace snake_case with camelCase in deployment.affinity.pod_anti - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment']['affinity'].pop('pod_anti') %} - {{ kiali_vars | combine({'deployment': {'affinity': {'pod_anti': current_cr.spec.deployment.affinity.pod_anti }}}, recursive=True) }} - when: - - kiali_vars.deployment.affinity is defined - - kiali_vars.deployment.affinity.pod_anti is defined - - kiali_vars.deployment.affinity.pod_anti | length > 0 - -- name: Replace snake_case with camelCase in deployment.tolerations - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment'].pop('tolerations') %} - {{ kiali_vars | combine({'deployment': {'tolerations': current_cr.spec.deployment.tolerations }}, recursive=True) }} - when: - - kiali_vars.deployment.tolerations is defined - - kiali_vars.deployment.tolerations | length > 0 - -- name: Replace snake_case with camelCase in deployment.additional_service_yaml - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment'].pop('additional_service_yaml') %} - {{ kiali_vars | combine({'deployment': {'additional_service_yaml': current_cr.spec.deployment.additional_service_yaml }}, recursive=True) }} - when: - - kiali_vars.deployment.additional_service_yaml is defined - - kiali_vars.deployment.additional_service_yaml | length > 0 - -- name: Replace snake_case with camelCase in deployment.resources - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment'].pop('resources') %} - {{ kiali_vars | combine({'deployment': {'resources': current_cr.spec.deployment.resources }}, recursive=True) }} - when: - - kiali_vars.deployment.resources is defined - - kiali_vars.deployment.resources | length > 0 - -- name: Replace snake_case with camelCase in deployment.ingress.override_yaml - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment']['ingress'].pop('override_yaml') %} - {{ kiali_vars | combine({'deployment': {'ingress': {'override_yaml': current_cr.spec.deployment.ingress.override_yaml }}}, recursive=True) }} - when: - - kiali_vars.deployment.ingress.override_yaml is defined - - kiali_vars.deployment.ingress.override_yaml | length > 0 - -- name: Replace snake_case with camelCase in deployment.pod_annotations - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment'].pop('pod_annotations') %} - {{ kiali_vars | combine({'deployment': {'pod_annotations': current_cr.spec.deployment.pod_annotations }}, recursive=True) }} - when: - - kiali_vars.deployment.pod_annotations is defined - - kiali_vars.deployment.pod_annotations | length > 0 - -- name: Replace snake_case with camelCase in deployment.pod_labels - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment'].pop('pod_labels') %} - {{ kiali_vars | combine({'deployment': {'pod_labels': current_cr.spec.deployment.pod_labels }}, recursive=True) }} - when: - - kiali_vars.deployment.pod_labels is defined - - kiali_vars.deployment.pod_labels | length > 0 - -- name: Replace snake_case with camelCase in deployment.service_annotations - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment'].pop('service_annotations') %} - {{ kiali_vars | combine({'deployment': {'service_annotations': current_cr.spec.deployment.service_annotations }}, recursive=True) }} - when: - - kiali_vars.deployment.service_annotations is defined - - kiali_vars.deployment.service_annotations | length > 0 - -- name: Replace snake_case with camelCase in deployment.hpa.spec - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment']['hpa'].pop('spec') %} - {{ kiali_vars | combine({'deployment': {'hpa': {'spec': current_cr.spec.deployment.hpa.spec }}}, recursive=True) }} - when: - - kiali_vars.deployment.hpa is defined - - kiali_vars.deployment.hpa.spec is defined - - kiali_vars.deployment.hpa.spec | length > 0 - -- name: Replace snake_case with camelCase in deployment.node_selector - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment'].pop('node_selector') %} - {{ kiali_vars | combine({'deployment': {'node_selector': current_cr.spec.deployment.node_selector }}, recursive=True) }} - when: - - kiali_vars.deployment.node_selector is defined - - kiali_vars.deployment.node_selector | length > 0 - -- name: Replace snake_case with camelCase in external_services.custom_dashboards.prometheus.custom_headers - set_fact: - kiali_vars: | - {% set a=kiali_vars['external_services']['custom_dashboards']['prometheus'].pop('custom_headers') %} - {{ kiali_vars | combine({'external_services': {'custom_dashboards': {'prometheus': {'custom_headers': current_cr.spec.external_services.custom_dashboards.prometheus.custom_headers }}}}, recursive=True) }} - when: - - kiali_vars.external_services.custom_dashboards.prometheus.custom_headers is defined - - kiali_vars.external_services.custom_dashboards.prometheus.custom_headers | length > 0 - -- name: Replace snake_case with camelCase in external_services.custom_dashboards.prometheus.query_scope - set_fact: - kiali_vars: | - {% set a=kiali_vars['external_services']['custom_dashboards']['prometheus'].pop('query_scope') %} - {{ kiali_vars | combine({'external_services': {'custom_dashboards': {'prometheus': {'query_scope': current_cr.spec.external_services.custom_dashboards.prometheus.query_scope }}}}, recursive=True) }} - when: - - kiali_vars.external_services.custom_dashboards.prometheus.query_scope is defined - - kiali_vars.external_services.custom_dashboards.prometheus.query_scope | length > 0 - -- name: Replace snake_case with camelCase in external_services.prometheus.custom_headers - set_fact: - kiali_vars: | - {% set a=kiali_vars['external_services']['prometheus'].pop('custom_headers') %} - {{ kiali_vars | combine({'external_services': {'prometheus': {'custom_headers': current_cr.spec.external_services.prometheus.custom_headers }}}, recursive=True) }} - when: - - kiali_vars.external_services.prometheus.custom_headers is defined - - kiali_vars.external_services.prometheus.custom_headers | length > 0 - -- name: Replace snake_case with camelCase in external_services.prometheus.query_scope - set_fact: - kiali_vars: | - {% set a=kiali_vars['external_services']['prometheus'].pop('query_scope') %} - {{ kiali_vars | combine({'external_services': {'prometheus': {'query_scope': current_cr.spec.external_services.prometheus.query_scope }}}, recursive=True) }} - when: - - kiali_vars.external_services.prometheus.query_scope is defined - - kiali_vars.external_services.prometheus.query_scope | length > 0 - -- name: Replace snake_case with camelCase in deployment.configmap_annotations - set_fact: - kiali_vars: | - {% set a=kiali_vars['deployment'].pop('configmap_annotations') %} - {{ kiali_vars | combine({'deployment': {'configmap_annotations': current_cr.spec.deployment.configmap_annotations }}, recursive=True) }} - when: - - kiali_vars.deployment.configmap_annotations is defined - - kiali_vars.deployment.configmap_annotations | length > 0 +# convert snake case to camelCase where appropriate +- include_tasks: snake_camel_case.yaml - name: Print some debug information vars: diff --git a/roles/default/kiali-deploy/tasks/snake_camel_case.yaml b/roles/default/kiali-deploy/tasks/snake_camel_case.yaml new file mode 100644 index 00000000..038c799e --- /dev/null +++ b/roles/default/kiali-deploy/tasks/snake_camel_case.yaml @@ -0,0 +1,160 @@ +# Because we are passing through some yaml directly to Kubernetes resources, we have to retain the camelCase keys. +# All CR parameters are converted to snake_case, but the original yaml is found in the special _kiali_io_kiali param. +# We need to copy that original yaml into our vars where appropriate to keep the camelCase. + +- name: Replace snake_case with camelCase in deployment.affinity.node + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment']['affinity'].pop('node') %} + {{ kiali_vars | combine({'deployment': {'affinity': {'node': current_cr.spec.deployment.affinity.node }}}, recursive=True) }} + when: + - kiali_vars.deployment.affinity is defined + - kiali_vars.deployment.affinity.node is defined + - kiali_vars.deployment.affinity.node | length > 0 + +- name: Replace snake_case with camelCase in deployment.affinity.pod + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment']['affinity'].pop('pod') %} + {{ kiali_vars | combine({'deployment': {'affinity': {'pod': current_cr.spec.deployment.affinity.pod }}}, recursive=True) }} + when: + - kiali_vars.deployment.affinity is defined + - kiali_vars.deployment.affinity.pod is defined + - kiali_vars.deployment.affinity.pod | length > 0 + +- name: Replace snake_case with camelCase in deployment.affinity.pod_anti + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment']['affinity'].pop('pod_anti') %} + {{ kiali_vars | combine({'deployment': {'affinity': {'pod_anti': current_cr.spec.deployment.affinity.pod_anti }}}, recursive=True) }} + when: + - kiali_vars.deployment.affinity is defined + - kiali_vars.deployment.affinity.pod_anti is defined + - kiali_vars.deployment.affinity.pod_anti | length > 0 + +- name: Replace snake_case with camelCase in deployment.tolerations + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment'].pop('tolerations') %} + {{ kiali_vars | combine({'deployment': {'tolerations': current_cr.spec.deployment.tolerations }}, recursive=True) }} + when: + - kiali_vars.deployment.tolerations is defined + - kiali_vars.deployment.tolerations | length > 0 + +- name: Replace snake_case with camelCase in deployment.additional_service_yaml + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment'].pop('additional_service_yaml') %} + {{ kiali_vars | combine({'deployment': {'additional_service_yaml': current_cr.spec.deployment.additional_service_yaml }}, recursive=True) }} + when: + - kiali_vars.deployment.additional_service_yaml is defined + - kiali_vars.deployment.additional_service_yaml | length > 0 + +- name: Replace snake_case with camelCase in deployment.resources + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment'].pop('resources') %} + {{ kiali_vars | combine({'deployment': {'resources': current_cr.spec.deployment.resources }}, recursive=True) }} + when: + - kiali_vars.deployment.resources is defined + - kiali_vars.deployment.resources | length > 0 + +- name: Replace snake_case with camelCase in deployment.ingress.override_yaml + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment']['ingress'].pop('override_yaml') %} + {{ kiali_vars | combine({'deployment': {'ingress': {'override_yaml': current_cr.spec.deployment.ingress.override_yaml }}}, recursive=True) }} + when: + - kiali_vars.deployment.ingress.override_yaml is defined + - kiali_vars.deployment.ingress.override_yaml | length > 0 + +- name: Replace snake_case with camelCase in deployment.pod_annotations + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment'].pop('pod_annotations') %} + {{ kiali_vars | combine({'deployment': {'pod_annotations': current_cr.spec.deployment.pod_annotations }}, recursive=True) }} + when: + - kiali_vars.deployment.pod_annotations is defined + - kiali_vars.deployment.pod_annotations | length > 0 + +- name: Replace snake_case with camelCase in deployment.pod_labels + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment'].pop('pod_labels') %} + {{ kiali_vars | combine({'deployment': {'pod_labels': current_cr.spec.deployment.pod_labels }}, recursive=True) }} + when: + - kiali_vars.deployment.pod_labels is defined + - kiali_vars.deployment.pod_labels | length > 0 + +- name: Replace snake_case with camelCase in deployment.service_annotations + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment'].pop('service_annotations') %} + {{ kiali_vars | combine({'deployment': {'service_annotations': current_cr.spec.deployment.service_annotations }}, recursive=True) }} + when: + - kiali_vars.deployment.service_annotations is defined + - kiali_vars.deployment.service_annotations | length > 0 + +- name: Replace snake_case with camelCase in deployment.hpa.spec + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment']['hpa'].pop('spec') %} + {{ kiali_vars | combine({'deployment': {'hpa': {'spec': current_cr.spec.deployment.hpa.spec }}}, recursive=True) }} + when: + - kiali_vars.deployment.hpa is defined + - kiali_vars.deployment.hpa.spec is defined + - kiali_vars.deployment.hpa.spec | length > 0 + +- name: Replace snake_case with camelCase in deployment.node_selector + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment'].pop('node_selector') %} + {{ kiali_vars | combine({'deployment': {'node_selector': current_cr.spec.deployment.node_selector }}, recursive=True) }} + when: + - kiali_vars.deployment.node_selector is defined + - kiali_vars.deployment.node_selector | length > 0 + +- name: Replace snake_case with camelCase in external_services.custom_dashboards.prometheus.custom_headers + set_fact: + kiali_vars: | + {% set a=kiali_vars['external_services']['custom_dashboards']['prometheus'].pop('custom_headers') %} + {{ kiali_vars | combine({'external_services': {'custom_dashboards': {'prometheus': {'custom_headers': current_cr.spec.external_services.custom_dashboards.prometheus.custom_headers }}}}, recursive=True) }} + when: + - kiali_vars.external_services.custom_dashboards.prometheus.custom_headers is defined + - kiali_vars.external_services.custom_dashboards.prometheus.custom_headers | length > 0 + +- name: Replace snake_case with camelCase in external_services.custom_dashboards.prometheus.query_scope + set_fact: + kiali_vars: | + {% set a=kiali_vars['external_services']['custom_dashboards']['prometheus'].pop('query_scope') %} + {{ kiali_vars | combine({'external_services': {'custom_dashboards': {'prometheus': {'query_scope': current_cr.spec.external_services.custom_dashboards.prometheus.query_scope }}}}, recursive=True) }} + when: + - kiali_vars.external_services.custom_dashboards.prometheus.query_scope is defined + - kiali_vars.external_services.custom_dashboards.prometheus.query_scope | length > 0 + +- name: Replace snake_case with camelCase in external_services.prometheus.custom_headers + set_fact: + kiali_vars: | + {% set a=kiali_vars['external_services']['prometheus'].pop('custom_headers') %} + {{ kiali_vars | combine({'external_services': {'prometheus': {'custom_headers': current_cr.spec.external_services.prometheus.custom_headers }}}, recursive=True) }} + when: + - kiali_vars.external_services.prometheus.custom_headers is defined + - kiali_vars.external_services.prometheus.custom_headers | length > 0 + +- name: Replace snake_case with camelCase in external_services.prometheus.query_scope + set_fact: + kiali_vars: | + {% set a=kiali_vars['external_services']['prometheus'].pop('query_scope') %} + {{ kiali_vars | combine({'external_services': {'prometheus': {'query_scope': current_cr.spec.external_services.prometheus.query_scope }}}, recursive=True) }} + when: + - kiali_vars.external_services.prometheus.query_scope is defined + - kiali_vars.external_services.prometheus.query_scope | length > 0 + +- name: Replace snake_case with camelCase in deployment.configmap_annotations + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment'].pop('configmap_annotations') %} + {{ kiali_vars | combine({'deployment': {'configmap_annotations': current_cr.spec.deployment.configmap_annotations }}, recursive=True) }} + when: + - kiali_vars.deployment.configmap_annotations is defined + - kiali_vars.deployment.configmap_annotations | length > 0