From 485fb93f789005464220572bc95a5a7d4dff12be Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 23 Nov 2026 15:08:02 +0100 Subject: [PATCH] fix(helm): render when an upgrade reuses values from before the database block The templates read the database settings through a default dict, so helm upgrade --reuse-values from a release without them no longer stops on a nil pointer; CI renders the chart with the block removed. --- .github/workflows/test.yml | 1 + charts/trek/templates/deployment.yaml | 9 +++++---- charts/trek/templates/secret.yaml | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 51ef16858..b5b626164 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1187,6 +1187,7 @@ jobs: --set 'extraVolumeMounts[0].mountPath=/usr/local/share/kitinerary/extractors' \ --set 'extraVolumeMounts[0].readOnly=true' \ --set probes.liveness=null \ + --set database=null \ > "$out/variants.yaml" helm template trek charts/trek \ --set httpRoute.enabled=true \ diff --git a/charts/trek/templates/deployment.yaml b/charts/trek/templates/deployment.yaml index fe844e908..19ffbe877 100644 --- a/charts/trek/templates/deployment.yaml +++ b/charts/trek/templates/deployment.yaml @@ -1,4 +1,5 @@ -{{- if and .Values.database.url (not .Values.database.existingSecret) .Values.existingSecret }} +{{- $db := default dict .Values.database }} +{{- if and $db.url (not $db.existingSecret) .Values.existingSecret }} {{- fail "database.url is written into the chart's own Secret, which existingSecret replaces. Put TREK_DB_URL in your Secret and set database.existingSecret instead." }} {{- end }} apiVersion: apps/v1 @@ -66,13 +67,13 @@ spec: name: {{ default (printf "%s-secret" (include "trek.fullname" .)) .Values.existingSecret }} key: {{ .Values.existingSecretKey | default "ENCRYPTION_KEY" }} optional: true - {{- if or .Values.database.url .Values.database.existingSecret }} + {{- if or $db.url $db.existingSecret }} # Required when set: a missing key stops the pod rather than starting it on SQLite. - name: TREK_DB_URL valueFrom: secretKeyRef: - name: {{ default (printf "%s-secret" (include "trek.fullname" .)) .Values.database.existingSecret }} - key: {{ if .Values.database.existingSecret }}{{ .Values.database.existingSecretKey | default "TREK_DB_URL" }}{{ else }}TREK_DB_URL{{ end }} + name: {{ default (printf "%s-secret" (include "trek.fullname" .)) $db.existingSecret }} + key: {{ if $db.existingSecret }}{{ $db.existingSecretKey | default "TREK_DB_URL" }}{{ else }}TREK_DB_URL{{ end }} {{- end }} - name: ADMIN_EMAIL valueFrom: diff --git a/charts/trek/templates/secret.yaml b/charts/trek/templates/secret.yaml index f9c1440e2..07c7099bf 100644 --- a/charts/trek/templates/secret.yaml +++ b/charts/trek/templates/secret.yaml @@ -1,3 +1,4 @@ +{{- $db := default dict .Values.database }} {{- if and (not .Values.existingSecret) (not .Values.generateEncryptionKey) }} apiVersion: v1 kind: Secret @@ -8,8 +9,8 @@ metadata: type: Opaque data: {{ .Values.existingSecretKey | default "ENCRYPTION_KEY" }}: {{ .Values.secretEnv.ENCRYPTION_KEY | b64enc | quote }} - {{- if .Values.database.url }} - TREK_DB_URL: {{ .Values.database.url | b64enc | quote }} + {{- if $db.url }} + TREK_DB_URL: {{ $db.url | b64enc | quote }} {{- end }} {{- if .Values.secretEnv.ADMIN_EMAIL }} ADMIN_EMAIL: {{ .Values.secretEnv.ADMIN_EMAIL | b64enc | quote }} @@ -68,8 +69,8 @@ stringData: {{- else }} {{ .Values.existingSecretKey | default "ENCRYPTION_KEY" }}: {{ randAlphaNum 32 | quote }} {{- end }} - {{- if .Values.database.url }} - TREK_DB_URL: {{ .Values.database.url | quote }} + {{- if $db.url }} + TREK_DB_URL: {{ $db.url | quote }} {{- end }} {{- if .Values.secretEnv.ADMIN_EMAIL }} ADMIN_EMAIL: {{ .Values.secretEnv.ADMIN_EMAIL | quote }}