Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor large blob of code that converts yaml from snake case to camel case #551

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 2 additions & 160 deletions roles/default/kiali-deploy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
160 changes: 160 additions & 0 deletions roles/default/kiali-deploy/tasks/snake_camel_case.yaml
Original file line number Diff line number Diff line change
@@ -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