From 0602ca221b8fd0618f48cd3025f54c284f8c885e Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Mon, 24 Apr 2023 03:36:13 +0200
Subject: [PATCH] fix(hedgedoc): Rework secret handling for postgresql

If one doesn't render the subchart, it's not very surprising that it
might doesn't create the correct secrets.
---
 charts/hedgedoc/Chart.yaml                | 2 +-
 charts/hedgedoc/README.md                 | 2 +-
 charts/hedgedoc/templates/deployment.yaml | 2 ++
 charts/hedgedoc/templates/secret.yaml     | 5 +++++
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/charts/hedgedoc/Chart.yaml b/charts/hedgedoc/Chart.yaml
index f163c47cf..e490d13bd 100644
--- a/charts/hedgedoc/Chart.yaml
+++ b/charts/hedgedoc/Chart.yaml
@@ -11,7 +11,7 @@ keywords:
 sources:
     - https://github.com/hedgedoc/hedgedoc/tree/master
     - https://git.shivering-isles.com/shivering-isles/infrastructure-gitops/-/tree/main/charts/hedgedoc
-version: 0.1.3
+version: 0.1.4
 # renovate: image=quay.io/hedgedoc/hedgedoc
 appVersion: 1.9.7
 maintainers:
diff --git a/charts/hedgedoc/README.md b/charts/hedgedoc/README.md
index dceb58f28..64fe6fd09 100644
--- a/charts/hedgedoc/README.md
+++ b/charts/hedgedoc/README.md
@@ -1,6 +1,6 @@
 # hedgedoc
 
-![Version: 0.1.3](https://img.shields.io/badge/Version-0.1.3-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.9.7](https://img.shields.io/badge/AppVersion-1.9.7-informational?style=flat-square)
+![Version: 0.1.4](https://img.shields.io/badge/Version-0.1.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.9.7](https://img.shields.io/badge/AppVersion-1.9.7-informational?style=flat-square)
 
 A platform to write and share markdown.
 
diff --git a/charts/hedgedoc/templates/deployment.yaml b/charts/hedgedoc/templates/deployment.yaml
index 4e926e5a6..38343b1ee 100644
--- a/charts/hedgedoc/templates/deployment.yaml
+++ b/charts/hedgedoc/templates/deployment.yaml
@@ -37,11 +37,13 @@ spec:
             - configMapRef:
                 name: {{ include "hedgedoc.fullname" . }}
           env:
+            {{- if (or .Values.postgresql.enabled .Values.postgresql.auth.existingSecret) }}
             - name: "CMD_DB_PASSWORD"
               valueFrom:
                 secretKeyRef:
                   name: {{ template "hedgedoc.postgresql.secretName" . }}
                   key: password
+            {{- end }}
           ports:
             - name: http
               containerPort: 3000
diff --git a/charts/hedgedoc/templates/secret.yaml b/charts/hedgedoc/templates/secret.yaml
index 437bca31d..a3c53d8f4 100644
--- a/charts/hedgedoc/templates/secret.yaml
+++ b/charts/hedgedoc/templates/secret.yaml
@@ -23,4 +23,9 @@ data:
   {{- end }}
   {{- with .Values.config.oauth.clientSecret }}
   CMD_OAUTH2_CLIENT_SECRET: {{ . | b64enc }}
+  {{- end }}
+  {{- if not .Values.postgresql.enabled }}
+  {{- if not .Values.postgresql.auth.existingSecret }}
+  CMD_DB_PASSWORD: "{{ .Values.postgresql.auth.password | b64enc }}"
+  {{- end }}
   {{- end }}
\ No newline at end of file
-- 
GitLab