Prevent garm db passphrase regeneration on redeployment

This commit is contained in:
Martin McCaffery 2025-12-22 10:29:24 +01:00
parent 8e6647a86f
commit b46e1d03b5
Signed by: martin.mccaffery
GPG key ID: 7C4D0F375BCEE533
2 changed files with 19 additions and 4 deletions

View file

@ -44,10 +44,9 @@ Get Gitea token - either user-provided or generated
{{- end -}} {{- end -}}
{{- define "garm.dbPassphrase" -}} {{- define "garm.dbPassphrase" -}}
{{- $secret := lookup "v1" "Secret" .Release.Namespace (printf "%s-config" ( include "garm.fullname" . )) -}} {{- $secret := lookup "v1" "Secret" .Release.Namespace (printf "%s-db-credentials" ( include "garm.fullname" . )) -}}
{{- if and $secret ((fromToml (index $secret.data "config.toml" | b64dec)).database.passphrase) -}} {{- if and $secret (index $secret.data "passphrase" | b64dec) -}}
{{- $another := fromToml (index $secret.data "config.toml" | b64dec) -}} {{- (index $secret.data "passphrase" | b64dec) -}}
{{ $another.database.passphrase }}
{{- else -}} {{- else -}}
{{- include "garm.randomString" . -}} {{- include "garm.randomString" . -}}
{{- end -}} {{- end -}}

View file

@ -14,6 +14,22 @@ stringData:
GARM_URL: {{ printf "https://%s" (index .Values.ingress.hosts 0).host | quote }} GARM_URL: {{ printf "https://%s" (index .Values.ingress.hosts 0).host | quote }}
GIT_URL: {{ .Values.credentials.gitea.url | quote }} GIT_URL: {{ .Values.credentials.gitea.url | quote }}
--- ---
{{- $secretName := printf "%s%s" (include "garm.fullname" .) "-db-credentials" -}}
{{- $secretExists := lookup "v1" "Secret" .Release.Namespace $secretName -}}
{{- if not $secretExists -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ $secretName }}
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
stringData:
passphrase: {{- include "garm.randomString" . -}}
{{- end -}}
---
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
metadata: metadata: