From f8a5bb4fd843863684e9477626289c4d601f21ee Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Thu, 17 Oct 2024 14:36:27 +0200
Subject: [PATCH] ozg-6945 make zufi-manager optional

---
 pom.xml                                       |  2 +-
 src/main/helm/templates/_helpers.tpl          |  4 ++
 src/main/helm/templates/deployment.yaml       |  8 ++-
 src/main/helm/values.yaml                     |  3 -
 ...ployment_zufimanager_address_env_test.yaml | 57 ++++++++++++-------
 5 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/pom.xml b/pom.xml
index c6fdcb12d..71218a6de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>de.ozgcloud.vorgang</groupId>
 	<artifactId>vorgang-manager</artifactId>
-	<version>2.16.0</version>
+	<version>2.16.1-SNAPSHOT</version>
 
 	<name>OZG-Cloud Vorgang Manager</name>
 	<packaging>pom</packaging>
diff --git a/src/main/helm/templates/_helpers.tpl b/src/main/helm/templates/_helpers.tpl
index fe0cc4a15..dd9bf30b9 100644
--- a/src/main/helm/templates/_helpers.tpl
+++ b/src/main/helm/templates/_helpers.tpl
@@ -163,3 +163,7 @@ app.kubernetes.io/namespace: {{ include "app.namespace" . }}
 {{ printf "https://%s.%s" (include "app.ozgcloudBezeichner" .) (include "app.baseUrl" .) }}
 {{- end -}}
 {{- end -}}
+
+{{- define "app.zufiManagerAddress" -}}
+{{- required "zufiManager.address must be set" (.Values.zufiManager).address -}}
+{{- end -}}
\ No newline at end of file
diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml
index 52451fef2..376274308 100644
--- a/src/main/helm/templates/deployment.yaml
+++ b/src/main/helm/templates/deployment.yaml
@@ -155,12 +155,14 @@ spec:
 
           - name: ozgcloud_user-manager_url
             value: {{ include "app.ozgcloud_migration_user-manager_address" . }}
+          {{- if (.Values.zufiManager).enabled }}
           - name: ozgcloud_zufi-manager_address
-            value: {{ (.Values.zufiManager).address }}
+            value: {{ include "app.zufiManagerAddress" . }}
           - name: grpc_client_zufi-manager_address
-            value: {{ (.Values.zufiManager).address }}
+            value: {{ include "app.zufiManagerAddress" . }}
           - name: grpc_client_zufi-manager_negotiationType
-            value: {{ (.Values.zufiManager).grpcClientNegotiationType }}
+            value: {{ (.Values.zufiManager).grpcClientNegotiationType | default "PLAINTEXT" }}
+          {{- end}}
           {{- if not (.Values.database).useExternal }}
           - name: spring_data_mongodb_uri
             valueFrom:
diff --git a/src/main/helm/values.yaml b/src/main/helm/values.yaml
index e5d0d6e27..832dfa01e 100644
--- a/src/main/helm/values.yaml
+++ b/src/main/helm/values.yaml
@@ -57,9 +57,6 @@ usermanagerName: user-manager
 
 administrationName: administration
 
-zufiManager:
-  address: dns:///zufi-server.zufi:9090
-
 elasticsearch:
     certificateSecretName: elasticsearch-certificate
 
diff --git a/src/test/helm/deployment_zufimanager_address_env_test.yaml b/src/test/helm/deployment_zufimanager_address_env_test.yaml
index 103ab80b2..dfb89d3f4 100644
--- a/src/test/helm/deployment_zufimanager_address_env_test.yaml
+++ b/src/test/helm/deployment_zufimanager_address_env_test.yaml
@@ -35,51 +35,70 @@ set:
     bezeichner: helm
   imagePullSecret: test-image-pull-secret
 tests:
-  - it: check default zufi-manager address
+  - it: zufi-manager should be disabled by default
     asserts:
-      - contains:
+      - notContains:
           path: spec.template.spec.containers[0].env
           content:
             name: ozgcloud_zufi-manager_address
-            value: dns:///zufi-server.zufi:9090
+          any: true
+      - notContains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: grpc_client_zufi-manager_address
+          any: true
+      - notContains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: grpc_client_zufi-manager_negotiationType
+          any: true
 
-  - it: should set custom zufi-manager address
+  - it: should require zufi-manager address
     set:
       zufiManager:
-        address: dns://other.zufi:9090
+        enabled: true
     asserts:
-      - contains:
-          path: spec.template.spec.containers[0].env
-          content:
-            name: ozgcloud_zufi-manager_address
-            value: dns://other.zufi:9090
+      - failedTemplate:
+          errorMessage: "zufiManager.address must be set"
 
-  - it: check default zufi-manager grpc client address
+  - it: should set zufi-manager address
+    set:
+      zufiManager:
+        enabled: true
+        address: dns:///zufi-server.zufi-test:9090
     asserts:
       - contains:
           path: spec.template.spec.containers[0].env
           content:
             name: grpc_client_zufi-manager_address
-            value: dns:///zufi-server.zufi:9090
+            value: dns:///zufi-server.zufi-test:9090
+      - contains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: ozgcloud_zufi-manager_address
+            value: dns:///zufi-server.zufi-test:9090
 
-  - it: should set custom zufi-manager grpc client address
+  - it: check default zufi-manager grpc negotiationType
     set:
       zufiManager:
-        address: dns://other.zufi:9090
+        enabled: true
+        address: dns:///zufi-server.zufi-test:9090
     asserts:
       - contains:
           path: spec.template.spec.containers[0].env
           content:
-            name: grpc_client_zufi-manager_address
-            value: dns://other.zufi:9090
+            name: grpc_client_zufi-manager_negotiationType
+            value: PLAINTEXT
 
-  - it: check if zufi-manager negotiationType is set
+  - it: should set zufi-manager negotiationType
     set:
       zufiManager:
-        grpcClientNegotiationType: NOT_DEFAULT
+        enabled: true
+        address: dns:///zufi-server.zufi-test:9090
+        grpcClientNegotiationType: TLS
     asserts:
       - contains:
           path: spec.template.spec.containers[0].env
           content:
             name: grpc_client_zufi-manager_negotiationType
-            value: NOT_DEFAULT
+            value: TLS
-- 
GitLab