From f8c84c4f5b896bb0450669e87a03b2afd1362eca Mon Sep 17 00:00:00 2001
From: Michael Koch <michael.koch@open-xchange.com>
Date: Fri, 12 Jul 2024 10:59:00 +0200
Subject: [PATCH] Helm: Fix helm chart rendering when authentication is enabled

---
 .gitignore                                    |  1 +
 helm/core-ui-middleware/Chart.lock            |  6 ------
 helm/core-ui-middleware/Chart.yaml            |  2 +-
 .../templates/deployment.yaml                 | 21 ++++++++++++++++++-
 .../templates/redis-secret.yaml               |  4 +++-
 helm/core-ui-middleware/values.yaml           |  4 +++-
 6 files changed, 28 insertions(+), 10 deletions(-)
 delete mode 100644 helm/core-ui-middleware/Chart.lock

diff --git a/.gitignore b/.gitignore
index dfd191d..1634e47 100644
--- a/.gitignore
+++ b/.gitignore
@@ -126,4 +126,5 @@ Thumbs.db
 output
 package-lock.json
 helm/core-ui-middleware/charts/
+helm/core-ui-middleware/Chart.lock
 .pnpm-store
diff --git a/helm/core-ui-middleware/Chart.lock b/helm/core-ui-middleware/Chart.lock
deleted file mode 100644
index 1fc5f86..0000000
--- a/helm/core-ui-middleware/Chart.lock
+++ /dev/null
@@ -1,6 +0,0 @@
-dependencies:
-- name: ox-common
-  repository: oci://registry.open-xchange.com/appsuite-core-internal/charts
-  version: 1.0.41
-digest: sha256:c86cf38308398f1458863f3b6f8f9aa35effd251df7ba847547b40dacdaab99e
-generated: "2024-05-16T10:39:00.523895345Z"
diff --git a/helm/core-ui-middleware/Chart.yaml b/helm/core-ui-middleware/Chart.yaml
index 8e41c71..f063e34 100644
--- a/helm/core-ui-middleware/Chart.yaml
+++ b/helm/core-ui-middleware/Chart.yaml
@@ -15,7 +15,7 @@ type: application
 # This is the chart version. This version number should be incremented each time you make changes
 # to the chart and its templates, including the app version.
 # Versions are expected to follow Semantic Versioning (https://semver.org/)
-version: 3.0.9
+version: 3.0.10
 
 # This is the version number of the application being deployed. This version number should be
 # incremented each time you make changes to the application. Versions are not expected to
diff --git a/helm/core-ui-middleware/templates/deployment.yaml b/helm/core-ui-middleware/templates/deployment.yaml
index fcff7d5..7474aca 100644
--- a/helm/core-ui-middleware/templates/deployment.yaml
+++ b/helm/core-ui-middleware/templates/deployment.yaml
@@ -139,10 +139,29 @@ spec:
               value: "{{ .Values.redis.hosts | join "," }}"
             - name: REDIS_DB
               value: "{{ .Values.redis.db | int }}"
+            {{- if .Values.redis.auth.enabled }}
+            - name: REDIS_USERNAME
+              valueFrom:
+                secretKeyRef:
+                  name: {{ include "core-ui-middleware.redisSecret" . }}
+                  key: username
             - name: REDIS_PASSWORD
-              value: "{{ .Values.redis.password }}"
+              valueFrom:
+                secretKeyRef:
+                  name: {{ include "core-ui-middleware.redisSecret" . }}
+                  key: password
+            {{- end }}
             - name: REDIS_PREFIX
               value: "{{ .Values.redis.prefix }}"
+            - name: REDIS_TLS_ENABLED
+              value: "{{ .Values.redis.tls.enabled }}"
+            {{- if .Values.redis.tls.enabled }}
+            - name: REDIS_TLS_CA
+              valueFrom:
+                secretKeyRef:
+                  name: {{ include "core-ui-middleware.redisSecret" . }}
+                  key: ca.crt
+            {{- end }}
           resources:
             {{- toYaml .Values.updater.resources | nindent 12 }}
           volumeMounts:
diff --git a/helm/core-ui-middleware/templates/redis-secret.yaml b/helm/core-ui-middleware/templates/redis-secret.yaml
index 5a160d9..b4247c1 100644
--- a/helm/core-ui-middleware/templates/redis-secret.yaml
+++ b/helm/core-ui-middleware/templates/redis-secret.yaml
@@ -1,4 +1,4 @@
-{{- if or .Values.redis.auth.enabled  .Values.redis.tls.enabled -}}
+{{- if and (or .Values.redis.auth.enabled .Values.redis.tls.enabled) (not .Values.overrides.redisSecret) -}}
 apiVersion: v1
 kind: Secret
 metadata:
@@ -7,5 +7,7 @@ type: Opaque
 data:
   username: {{ .Values.redis.auth.username | b64enc | quote }}
   password: {{ .Values.redis.auth.password | b64enc | quote }}
+  {{- if and .Values.redis.tls.enabled .Values.redis.tls.ca }}
   ca.crt: {{ .Values.redis.tls.ca | b64enc | quote }}
+  {{- end }}
 {{- end -}}
diff --git a/helm/core-ui-middleware/values.yaml b/helm/core-ui-middleware/values.yaml
index 0842833..72cde62 100644
--- a/helm/core-ui-middleware/values.yaml
+++ b/helm/core-ui-middleware/values.yaml
@@ -14,7 +14,7 @@ defaultRegistry: registry.open-xchange.com
 containerPort: 8080
 
 image:
-  repository: "core-ui-middleware"
+  repository: "appsuite-core-internal/core-ui-middleware"
   pullPolicy: IfNotPresent
   # Overrides the image tag whose default is the chart appVersion.
   tag: ""
@@ -22,6 +22,8 @@ image:
 imagePullSecrets: []
 nameOverride: ""
 fullnameOverride: ""
+overrides: {}
+#  redisSecret: ""
 
 podAnnotations:
   logging.open-xchange.com/format: "appsuite-json"
-- 
GitLab