From 10ee0e6399d49c83be531801c473f39d0754a436 Mon Sep 17 00:00:00 2001 From: John Mazzitelli Date: Mon, 2 May 2022 15:39:53 -0400 Subject: [PATCH] be able to add containers to Kiali pod fixes: https://github.com/kiali/kiali/issues/5028 --- crd-docs/cr/kiali.io_v1alpha1_kiali.yaml | 1 + crd-docs/crd/kiali.io_kialis.yaml | 4 + roles/default/kiali-deploy/defaults/main.yml | 1 + roles/default/kiali-deploy/tasks/main.yml | 162 +---------------- .../kiali-deploy/tasks/snake_camel_case.yaml | 169 ++++++++++++++++++ .../templates/kubernetes/deployment.yaml | 3 + .../templates/openshift/deployment.yaml | 3 + 7 files changed, 183 insertions(+), 160 deletions(-) create mode 100644 roles/default/kiali-deploy/tasks/snake_camel_case.yaml diff --git a/crd-docs/cr/kiali.io_v1alpha1_kiali.yaml b/crd-docs/cr/kiali.io_v1alpha1_kiali.yaml index 29c6230b7..0295ec1c3 100644 --- a/crd-docs/cr/kiali.io_v1alpha1_kiali.yaml +++ b/crd-docs/cr/kiali.io_v1alpha1_kiali.yaml @@ -57,6 +57,7 @@ spec: deployment: accessible_namespaces: ["^((?!(istio-operator|kube-.*|openshift.*|ibm.*|kiali-operator)).)*$"] + additional_pod_containers_yaml: {} # default: additional_service_yaml is empty additional_service_yaml: externalName: "kiali.example.com" diff --git a/crd-docs/crd/kiali.io_kialis.yaml b/crd-docs/crd/kiali.io_kialis.yaml index 3df5fb318..33fd727e9 100644 --- a/crd-docs/crd/kiali.io_kialis.yaml +++ b/crd-docs/crd/kiali.io_kialis.yaml @@ -217,6 +217,10 @@ spec: type: array items: type: string + additional_pod_containers_yaml: + description: "Additional containers to add to the list of pod containers. Use this to add a sidecar(s) to the Kiali pod. Use with care since sidecars may cause the Kiali container itself to operate incorrectly. It is up to the user who added the additional containers to ensure it works properly inside the Kiali pod; Kiali makes no guarantee additional containers will work." + type: object + x-kubernetes-preserve-unknown-fields: true additional_service_yaml: description: "Additional custom yaml to add to the service definition. This is used mainly to customize the service type. For example, if the `deployment.service_type` is set to 'LoadBalancer' and you want to set the loadBalancerIP, you can do so here with: `additional_service_yaml: { 'loadBalancerIP': '78.11.24.19' }`. Another example would be if the `deployment.service_type` is set to 'ExternalName' you will need to configure the name via: `additional_service_yaml: { 'externalName': 'my.kiali.example.com' }`. A final example would be if external IPs need to be set: `additional_service_yaml: { 'externalIPs': ['80.11.12.10'] }`" type: object diff --git a/roles/default/kiali-deploy/defaults/main.yml b/roles/default/kiali-deploy/defaults/main.yml index aa90d993b..8dadf44c6 100644 --- a/roles/default/kiali-deploy/defaults/main.yml +++ b/roles/default/kiali-deploy/defaults/main.yml @@ -52,6 +52,7 @@ kiali_defaults: deployment: accessible_namespaces: ["^((?!(istio-operator|kube-.*|openshift.*|ibm.*|kiali-operator)).)*$"] + additional_pod_containers_yaml: {} #additional_service_yaml: affinity: node: {} diff --git a/roles/default/kiali-deploy/tasks/main.yml b/roles/default/kiali-deploy/tasks/main.yml index 58c107142..841c1dd42 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 000000000..ddca89ac8 --- /dev/null +++ b/roles/default/kiali-deploy/tasks/snake_camel_case.yaml @@ -0,0 +1,169 @@ +# 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 + +- name: Replace snake_case with camelCase in deployment.additional_pod_containers_yaml + set_fact: + kiali_vars: | + {% set a=kiali_vars['deployment'].pop('additional_pod_containers_yaml') %} + {{ kiali_vars | combine({'deployment': {'additional_pod_containers_yaml': current_cr.spec.deployment.additional_pod_containers_yaml }}, recursive=True) }} + when: + - kiali_vars.deployment.additional_pod_containers_yaml is defined + - kiali_vars.deployment.additional_pod_containers_yaml | length > 0 diff --git a/roles/default/kiali-deploy/templates/kubernetes/deployment.yaml b/roles/default/kiali-deploy/templates/kubernetes/deployment.yaml index f9d1106e2..312b47719 100644 --- a/roles/default/kiali-deploy/templates/kubernetes/deployment.yaml +++ b/roles/default/kiali-deploy/templates/kubernetes/deployment.yaml @@ -117,6 +117,9 @@ spec: {{ kiali_vars.deployment.resources | to_nice_yaml(indent=0) | trim | indent(10) }} {% else %} resources: null +{% endif %} +{% if kiali_vars.deployment.additional_pod_containers_yaml|length > 0 %} + {{ kiali_vars.deployment.additional_pod_containers_yaml | to_nice_yaml(indent=0) | trim | indent(6) }} {% endif %} volumes: - name: kiali-configuration diff --git a/roles/default/kiali-deploy/templates/openshift/deployment.yaml b/roles/default/kiali-deploy/templates/openshift/deployment.yaml index ec1750e28..6a89d13aa 100644 --- a/roles/default/kiali-deploy/templates/openshift/deployment.yaml +++ b/roles/default/kiali-deploy/templates/openshift/deployment.yaml @@ -121,6 +121,9 @@ spec: {{ kiali_vars.deployment.resources | to_nice_yaml(indent=0) | trim | indent(10) }} {% else %} resources: null +{% endif %} +{% if kiali_vars.deployment.additional_pod_containers_yaml|length > 0 %} + {{ kiali_vars.deployment.additional_pod_containers_yaml | to_nice_yaml(indent=0) | trim | indent(6) }} {% endif %} volumes: - name: kiali-configuration