From 84c6d9585f87fb8d40c790482efb9fa1325c69a9 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Tue, 6 Feb 2024 10:11:18 +0100
Subject: [PATCH] OZG-4800-refactor baseUrl, baseDomain and add helm unnittests

---
 src/main/helm/templates/_helpers.tpl    |  6 +++++-
 src/main/helm/templates/deployment.yaml |  2 +-
 src/main/helm/templates/ingress.yaml    |  4 ++--
 src/test/helm/ingress-nginx-tests.yaml  | 14 +++++++++++++-
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/main/helm/templates/_helpers.tpl b/src/main/helm/templates/_helpers.tpl
index 358e0f69..2160ca18 100644
--- a/src/main/helm/templates/_helpers.tpl
+++ b/src/main/helm/templates/_helpers.tpl
@@ -95,7 +95,11 @@ app.kubernetes.io/namespace: {{ include "app.namespace" . }}
 {{- end -}}
 
 {{- define "app.baseUrl" -}}
-{{ printf "https://%s-%s.%s" (include "app.ozgcloudBezeichner" .) (include "app.name" .) .Values.baseUrl }}
+{{- required "baseUrl muss angegeben sein" .Values.baseUrl }}
+{{- end -}}
+
+{{- define "app.baseDomain" -}}
+{{ printf "%s-%s.%s" (include "app.ozgcloudBezeichner" .) (include "app.name" .) (include "app.baseUrl" .) }}
 {{- end -}}
 
 {{- define "app.alfaAddress" -}}
diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml
index 8aed2667..346ee183 100644
--- a/src/main/helm/templates/deployment.yaml
+++ b/src/main/helm/templates/deployment.yaml
@@ -100,7 +100,7 @@ spec:
         - name: KEYCLOAK_URL
           value: {{ include "app.ssoServerUrl" . }}
         - name: OZGCLOUD_USER_MANAGER_URL
-          value: {{ include "app.baseUrl" . }}
+          value: https://{{ include "app.baseDomain" . }}
         {{- if ((.Values.ozgcloud).usersync).period }}
         - name: OZGCLOUD_USERSYNC_PERIOD
           value: {{ .Values.ozgcloud.usersync.period }}
diff --git a/src/main/helm/templates/ingress.yaml b/src/main/helm/templates/ingress.yaml
index b10443e9..4b8a3497 100644
--- a/src/main/helm/templates/ingress.yaml
+++ b/src/main/helm/templates/ingress.yaml
@@ -54,10 +54,10 @@ spec:
                 name: {{ include "app.name" . }}
             path: ''
             pathType: ImplementationSpecific
-      host: {{ trimPrefix "https://" ( include "app.baseUrl" . ) }}
+      host: {{ ( include "app.baseDomain" . ) }}
   tls:
     - hosts:
-      - {{ trimPrefix "https://" ( include "app.baseUrl" . ) }}
+      - {{ ( include "app.baseDomain" . ) }}
       {{- if (.Values.ingress).tlsSecretName }}
       secretName: {{ (.Values.ingress).tlsSecretName }}
       {{- else if ne (.Values).cluster_env "dataport" }}
diff --git a/src/test/helm/ingress-nginx-tests.yaml b/src/test/helm/ingress-nginx-tests.yaml
index edc9075e..bd52d6a0 100644
--- a/src/test/helm/ingress-nginx-tests.yaml
+++ b/src/test/helm/ingress-nginx-tests.yaml
@@ -75,4 +75,16 @@ tests:
     asserts:
       - equal:
           path: metadata.annotations["cert-manager.io/cluster-issuer"]
-          value: letsencrypt-prod
\ No newline at end of file
+          value: letsencrypt-prod
+
+  - it: should create hostname correctly
+    asserts:
+      - equal:
+          path: spec.rules[0].host
+          value: helm-user-manager.test.sh.ozg-cloud.de
+
+  - it: should create tls hosts name correctly
+    asserts:
+      - equal:
+          path: spec.tls[0].hosts[0]
+          value: helm-user-manager.test.sh.ozg-cloud.de
\ No newline at end of file
-- 
GitLab