From 95946fd15842c27a5cda365221231defd79c5b88 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Wed, 19 Jun 2024 16:48:50 +0200
Subject: [PATCH] OZG-5958 add customVars for xta-adapter

---
 .../src/main/helm/templates/_helpers.tpl      | 17 +++++++++
 .../main/helm/templates/network_policy.yaml   |  7 ++++
 .../helm/templates/xta_adapter_cronjob.yaml   |  3 ++
 .../src/test/helm/network_policy_test.yaml    | 35 +++++++++++++++++++
 .../helm/xta_adapter_cronjob_env_test.yaml    | 31 +++++++++++++++-
 5 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/xta-adapter/src/main/helm/templates/_helpers.tpl b/xta-adapter/src/main/helm/templates/_helpers.tpl
index 5d09c8564..dbcecb22a 100644
--- a/xta-adapter/src/main/helm/templates/_helpers.tpl
+++ b/xta-adapter/src/main/helm/templates/_helpers.tpl
@@ -58,4 +58,21 @@ helm.sh/chart: {{ include "app.chart" . }}
 
 {{- define "app.serviceAccountName" -}}
 {{ printf "%s" ( (.Values.serviceAccount).name | default "xta-adapter-service-account" ) }}
+{{- 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/xta-adapter/src/main/helm/templates/network_policy.yaml b/xta-adapter/src/main/helm/templates/network_policy.yaml
index b65e30f07..9e04cc733 100644
--- a/xta-adapter/src/main/helm/templates/network_policy.yaml
+++ b/xta-adapter/src/main/helm/templates/network_policy.yaml
@@ -34,6 +34,13 @@ spec:
       ozg-component: xta-adapter
   policyTypes:
     - Egress
+  ingress:
+{{- with (.Values.networkPolicy).additionalIngressConfigLocal }}
+{{ toYaml . | indent 2 }}
+{{- end }}
+{{- with (.Values.networkPolicy).additionalIngressConfigGlobal }}
+{{ toYaml . | indent 2 }}
+{{- end }}
   egress:
   - to:
     - podSelector: 
diff --git a/xta-adapter/src/main/helm/templates/xta_adapter_cronjob.yaml b/xta-adapter/src/main/helm/templates/xta_adapter_cronjob.yaml
index 1159ff69e..b8d0d2b98 100644
--- a/xta-adapter/src/main/helm/templates/xta_adapter_cronjob.yaml
+++ b/xta-adapter/src/main/helm/templates/xta_adapter_cronjob.yaml
@@ -85,6 +85,9 @@ spec:
                 - name: grpc_client_vorgang-manager-{{ (.Values.routing).targetVorgangManagerName }}_negotiationType
                   value: {{ (.Values.routing).negotiationType | default "PLAINTEXT" }}
                 {{- end }}
+                {{- with include "app.getCustomList" . }}
+{{ . | indent 16 }}
+                {{- end }}
               volumeMounts:
                 - name: bindings
                   mountPath: "/bindings/ca-certificates/type"
diff --git a/xta-adapter/src/test/helm/network_policy_test.yaml b/xta-adapter/src/test/helm/network_policy_test.yaml
index 7e725ee8a..e6f423c44 100644
--- a/xta-adapter/src/test/helm/network_policy_test.yaml
+++ b/xta-adapter/src/test/helm/network_policy_test.yaml
@@ -56,6 +56,7 @@ tests:
                 ozg-component: xta-adapter
             policyTypes:
               - Egress
+            ingress:
             egress:
             - to:
               - podSelector: 
@@ -122,6 +123,40 @@ tests:
           - ipBlock:
               cidr: 1.2.3.4/32
 
+  - it: add ingress rule by values local
+    set:
+      networkPolicy:
+        dnsServerNamespace: test-namespace-dns
+        additionalIngressConfigLocal:
+        - from:
+          - podSelector: 
+              matchLabels:
+                component: client2
+    asserts:
+      - contains:
+          path: spec.ingress
+          content:
+            from:
+            - podSelector: 
+                matchLabels:
+                  component: client2
+  - it: add ingress rule by values global
+    set:
+      networkPolicy:
+        dnsServerNamespace: test-namespace-dns
+        additionalIngressConfigGlobal:
+        - from:
+          - podSelector: 
+              matchLabels:
+                component: client2
+    asserts:
+      - contains:
+          path: spec.ingress
+          content:
+            from:
+            - podSelector: 
+                matchLabels:
+                  component: client2
 
   - it: test network policy disabled
     set:
diff --git a/xta-adapter/src/test/helm/xta_adapter_cronjob_env_test.yaml b/xta-adapter/src/test/helm/xta_adapter_cronjob_env_test.yaml
index 4e84137ff..0a5f6345d 100644
--- a/xta-adapter/src/test/helm/xta_adapter_cronjob_env_test.yaml
+++ b/xta-adapter/src/test/helm/xta_adapter_cronjob_env_test.yaml
@@ -154,4 +154,33 @@ tests:
           path: spec.jobTemplate.spec.template.spec.containers[0].env
           content:
             name: grpc_client_vorgang-manager-vorgang-manager_negotiationType
-            value: "TLS"
\ No newline at end of file
+            value: "TLS"
+  - it: check customList as list
+    set:
+      env.customList:
+        - name: my_test_environment_name
+          value: "A test value"
+    asserts:
+      - contains:
+          path: spec.jobTemplate.spec.template.spec.containers[0].env
+          content:
+            name: my_test_environment_name
+            value: "A test value"
+  - it: check customList as dict
+    set:
+      env.customList:
+        my_test_environment_name: "A test value"
+    asserts:
+      - contains:
+          path: spec.jobTemplate.spec.template.spec.containers[0].env
+          content:
+            name: my_test_environment_name
+            value: "A test value"
+
+  - it: check customList test value is not set by default
+    asserts:
+      - notContains:
+          path: spec.jobTemplate.spec.template.spec.containers[0].env
+          content:
+            name: my_test_environment_name
+            value: "A test value"
\ No newline at end of file
-- 
GitLab