From b3047c438185d56b0d28be53ffd92a12196f4874 Mon Sep 17 00:00:00 2001
From: OZG-Cloud Team <noreply@ozg-sh.de>
Date: Tue, 23 Apr 2024 15:15:55 +0200
Subject: [PATCH] ozg-5100 customList as list or dict

---
 src/main/helm/README.md                         | 11 +++++++++--
 src/main/helm/templates/_helpers.tpl            | 17 +++++++++++++++++
 src/main/helm/templates/deployment.yaml         |  7 ++-----
 .../helm/deployment_env_customList_test.yaml    | 11 +++++------
 4 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/src/main/helm/README.md b/src/main/helm/README.md
index 464d5334..2de2b441 100644
--- a/src/main/helm/README.md
+++ b/src/main/helm/README.md
@@ -81,13 +81,20 @@ routing:
 
 ### Benutzung beliebiger environment Werte
 
-In jedem der Projekte kann man beliebige weitere environments setzen. Dazu muss man in der jeweiligen values.yaml unter env.customVarsLocal ein name value Paar setzen:
+In jedem der Projekte kann man beliebige weitere environments setzen. Dazu muss man in der jeweiligen values.yaml unter env.customList ein name value Paar setzen:
 
 ```yaml
 env:
-  customVarsLocal:
+  customList:
     - name: Dinge
       value: true
     - name: ...
       value: ...
 ```
+
+```yaml
+env:
+  customList:
+    key_1: value_1
+    key_2: value_2
+```
\ No newline at end of file
diff --git a/src/main/helm/templates/_helpers.tpl b/src/main/helm/templates/_helpers.tpl
index e0ff7ea4..4b113294 100644
--- a/src/main/helm/templates/_helpers.tpl
+++ b/src/main/helm/templates/_helpers.tpl
@@ -88,4 +88,21 @@ app.kubernetes.io/namespace: {{ include "app.namespace" . }}
 {{- else if eq (.Values.image).name "enterprise-adapter" }}
 {{- printf "enterprise-adapter-service-account" }}
 {{- end }}
+{{- end -}}
+
+{{- define "app.getCustomList" -}}
+{{- with (.Values.env).customList -}}
+{{- if kindIs "map" . -}}
+{{ include "app.dictToList" . }}
+{{- else if kindIs "slice" . -}}
+{{ . | toYaml }}
+{{- end -}}
+{{- end -}}
+{{- end -}}
+
+{{- define "app.dictToList" -}}
+{{- range $key, $value := . -}}
+- name: {{ $key }}
+  value: {{ $value }}
+{{- end -}}
 {{- end -}}
\ No newline at end of file
diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml
index 207444ad..c7e9bcd8 100644
--- a/src/main/helm/templates/deployment.yaml
+++ b/src/main/helm/templates/deployment.yaml
@@ -81,11 +81,8 @@ spec:
         - name: grpc_client_vorgang-manager-{{ (.Values.routing).targetVorgangManagerName}}_negotiationType
           value: {{ (.Values.routing).negotiationType | default "PLAINTEXT" }}
         {{- end }}
-        {{- with (.Values.env).customVarsLocal }}
-{{ toYaml . | indent 8 }}
-        {{- end }}
-        {{- with (.Values.env).customVarsGlobal }}
-{{ toYaml . | indent 8 }}
+        {{- with include "app.getCustomList" . }}
+{{ . | indent 8 }}
         {{- end }}
         image: "{{ .Values.image.repo }}/{{ .Values.image.name }}:{{ coalesce (.Values.image).tag "latest" }}"
         imagePullPolicy: Always
diff --git a/src/test/helm/deployment_env_customList_test.yaml b/src/test/helm/deployment_env_customList_test.yaml
index 8fe0b2be..8770315d 100644
--- a/src/test/helm/deployment_env_customList_test.yaml
+++ b/src/test/helm/deployment_env_customList_test.yaml
@@ -29,9 +29,9 @@ set:
   ozgcloud.environment: test
   imagePullSecret: image-pull-secret
 tests:
-  - it: check customVarsLocal
+  - it: check customList as list
     set:
-      env.customVarsLocal:
+      env.customList:
         - name: my_test_environment_name
           value: "A test value"
     asserts:
@@ -40,11 +40,10 @@ tests:
           content:
             name: my_test_environment_name
             value: "A test value"
-  - it: check customVarsGlobal
+  - it: check customList as dict
     set:
-      env.customVarsGlobal:
-        - name: my_test_environment_name
-          value: "A test value"
+      env.customList:
+        my_test_environment_name: "A test value"
     asserts:
       - contains:
           path: spec.template.spec.containers[0].env
-- 
GitLab