Skip to content

Commit

Permalink
be able to put custom annotations on the configmap (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmazzitelli authored Mar 21, 2022
1 parent 4870077 commit 8fa823a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions crd-docs/cr/kiali.io_v1alpha1_kiali.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ spec:
values:
- S2
topologyKey: topology.kubernetes.io/zone
# default: configmap_annotations is empty
configmap_annotations:
strategy.spinnaker.io/versioned: "false"
# default: custom_secrets is an empty list
custom_secrets:
- name: "a-custom-secret"
Expand Down
4 changes: 4 additions & 0 deletions crd-docs/crd/kiali.io_kialis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ spec:
pod_anti:
type: object
x-kubernetes-preserve-unknown-fields: true
configmap_annotations:
description: "Custom annotations to be created on the Kiali ConfigMap."
type: object
x-kubernetes-preserve-unknown-fields: true
custom_secrets:
description: |
Defines additional secrets that are to be mounted in the Kiali pod.
Expand Down
4 changes: 2 additions & 2 deletions molecule/common/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
vars:
instance_name: "{{ kiali.instance_name | default('kiali') }}"
set_fact:
kiali_configmap: "{{ lookup('kubernetes.core.k8s', api_version='v1', kind='ConfigMap', namespace=kiali.install_namespace, resource_name=instance_name) }}"
kiali_configmap_resource: "{{ lookup('kubernetes.core.k8s', api_version='v1', kind='ConfigMap', namespace=kiali.install_namespace, resource_name=instance_name) }}"

- name: Format Configmap
set_fact:
kiali_configmap: "{{ kiali_configmap.data['config.yaml'] | from_yaml }}"
kiali_configmap: "{{ kiali_configmap_resource.data['config.yaml'] | from_yaml }}"

- name: Get Kiali Deployment
vars:
Expand Down
13 changes: 12 additions & 1 deletion molecule/config-values-test/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
set_fact:
current_kiali_cr: "{{ current_kiali_cr | combine({'spec': {'login_token': {'signing_key': 'qazxsw0123456789'}}}, recursive=True) }}"

- name: Add configmap annotation
set_fact:
current_kiali_cr: "{{ current_kiali_cr | combine({'spec': {'deployment': {'configmap_annotations': {'aaa': 'bbb', 'camelCaseName': 'camelCaseValue'}}}}, recursive=True) }}"

- name: The new Kiali CR to be tested
debug:
msg: "{{ current_kiali_cr }}"
Expand Down Expand Up @@ -181,4 +185,11 @@
- name: Test the signing key is set
assert:
that:
- kiali_configmap.login_token.signing_key == 'qazxsw0123456789'
- kiali_configmap.login_token.signing_key == 'qazxsw0123456789'

- name: Make sure the configmap annotations made it to the configmap
assert:
that:
- kiali_configmap_resource.metadata.annotations.aaa == 'bbb'
- kiali_configmap_resource.metadata.annotations.camelCaseName == 'camelCaseValue'
fail_msg: "Missing configmap annotations: {{ kiali_configmap_resource }}"
1 change: 1 addition & 0 deletions roles/default/kiali-deploy/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ kiali_defaults:
node: {}
pod: {}
pod_anti: {}
configmap_annotations: {}
custom_secrets: []
host_aliases: []
hpa:
Expand Down
9 changes: 9 additions & 0 deletions roles/default/kiali-deploy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@
- 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: Print some debug information
vars:
msg: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ metadata:
name: {{ kiali_vars.deployment.instance_name }}
namespace: {{ kiali_vars.deployment.namespace }}
labels: {{ kiali_resource_metadata_labels }}
{% if kiali_vars.deployment.configmap_annotations is defined and kiali_vars.deployment.configmap_annotations|length > 0 %}
annotations:
{{ kiali_vars.deployment.configmap_annotations | to_nice_yaml(indent=0) | trim | indent(4) }}
{% endif %}
data:
config.yaml: |
{{ kiali_vars | to_nice_yaml(indent=0) | trim | indent(4) }}
4 changes: 4 additions & 0 deletions roles/default/kiali-deploy/templates/openshift/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ metadata:
name: {{ kiali_vars.deployment.instance_name }}
namespace: {{ kiali_vars.deployment.namespace }}
labels: {{ kiali_resource_metadata_labels }}
{% if kiali_vars.deployment.configmap_annotations is defined and kiali_vars.deployment.configmap_annotations|length > 0 %}
annotations:
{{ kiali_vars.deployment.configmap_annotations | to_nice_yaml(indent=0) | trim | indent(4) }}
{% endif %}
data:
config.yaml: |
{{ kiali_vars | to_nice_yaml(indent=0) | trim | indent(4) }}

0 comments on commit 8fa823a

Please sign in to comment.