From 94fbc5e38f1efd981bc88d2ae6d1e919ff2258a2 Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Tue, 26 Nov 2024 21:01:45 +0100 Subject: [PATCH] fix(deployment): concat lists correctly --- .../_deployment.tpl | 12 +++++----- unittests/deployment/deployment.yaml | 24 +++++++++++++------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/templates/prometheus-postgres-exporter/_deployment.tpl b/templates/prometheus-postgres-exporter/_deployment.tpl index d7cee1f..3cc9cf3 100644 --- a/templates/prometheus-postgres-exporter/_deployment.tpl +++ b/templates/prometheus-postgres-exporter/_deployment.tpl @@ -52,15 +52,15 @@ {{/* volumeMounts */}} {{- define "prometheus-postgres-exporter.deployment.volumeMounts" -}} -{{- $volumeMounts := dict "volumeMounts" (.Values.deployment.postgresExporter.volumeMounts | default (list) ) }} -{{- $volumeMounts = merge $volumeMounts (dict "volumeMounts" (list (dict "name" "config-d" "mountPath" "/etc/prometheus-postgres-exporter/config.d" ))) }} -{{ toYaml $volumeMounts }} +{{- $volumeMounts := .Values.deployment.postgresExporter.volumeMounts | default list }} +{{- $volumeMounts = concat $volumeMounts (list (dict "name" "config-d" "mountPath" "/etc/prometheus-postgres-exporter/config.d" )) }} +{{ toYaml (dict "volumeMounts" $volumeMounts) }} {{- end -}} {{/* volumes */}} {{- define "prometheus-postgres-exporter.deployment.volumes" -}} -{{- $volumes := dict "volumes" (.Values.deployment.volumes | default (list) ) }} +{{- $volumes := .Values.deployment.volumes | default list }} {{- $exporterSecretName := .Values.config.exporterConfig.existingSecret.secretName -}} {{- if not .Values.config.exporterConfig.existingSecret.enabled }} @@ -72,8 +72,8 @@ {{- $webConfigSecretName = printf "%s-web-config" (include "prometheus-postgres-exporter.fullname" . ) }} {{- end }} -{{- $volumes = merge $volumes (dict "volumes" (list (dict "name" "config-d" "projected" (dict "defaultMode" 444 "sources" (list (dict "secret" (dict "name" $exporterSecretName)) (dict "secret" (dict "name" $webConfigSecretName))))))) }} +{{- $volumes = concat $volumes (list (dict "name" "config-d" "projected" (dict "defaultMode" 444 "sources" (list (dict "secret" (dict "name" $exporterSecretName)) (dict "secret" (dict "name" $webConfigSecretName)))))) }} -{{ toYaml $volumes }} +{{ toYaml (dict "volumes" $volumes) }} {{- end -}} \ No newline at end of file diff --git a/unittests/deployment/deployment.yaml b/unittests/deployment/deployment.yaml index d562a71..5fdc25a 100644 --- a/unittests/deployment/deployment.yaml +++ b/unittests/deployment/deployment.yaml @@ -352,14 +352,24 @@ tests: hostPath: path: /usr/lib/prometheus-postgres-exporter/data asserts: - - contains: + - equal: path: spec.template.spec.containers[0].volumeMounts - content: - name: data + value: + - name: data mountPath: /usr/lib/prometheus-postgres-exporter/data - - contains: + - name: config-d + mountPath: /etc/prometheus-postgres-exporter/config.d + - equal: path: spec.template.spec.volumes - content: - name: data + value: + - name: data hostPath: - path: /usr/lib/prometheus-postgres-exporter/data \ No newline at end of file + path: /usr/lib/prometheus-postgres-exporter/data + - name: config-d + projected: + defaultMode: 444 + sources: + - secret: + name: prometheus-postgres-exporter-unittest-exporter-config + - secret: + name: prometheus-postgres-exporter-unittest-web-config \ No newline at end of file