Skip to content

Instantly share code, notes, and snippets.

@stand-sure
Created December 28, 2023 16:17
Show Gist options
  • Save stand-sure/053f38fa92da566ca53c2a3797b3d481 to your computer and use it in GitHub Desktop.
Save stand-sure/053f38fa92da566ca53c2a3797b3d481 to your computer and use it in GitHub Desktop.
helm random secret with persistence and optional override
{{- if empty .Values.manualSecretName }}
apiVersion: v1
kind: Secret
metadata:
name: "jwt-secret"
annotations:
"helm.sh/resource-policy": "keep"
type: Opaque
data:
# retrieve the secret data using lookup function and when not exists, return an empty dictionary / map as result
{{- $secretObj := (lookup "v1" "Secret" .Release.Namespace "jwt-secret") | default dict }}
{{- $secretData := (get $secretObj "data") | default dict }}
# set $jwtSecret to existing secret data or generate a random one when not exists
{{- $jwtSecret := (get $secretData "jwt-secret") | default (randAlphaNum 32 | b64enc) }}
jwt-secret: {{ $jwtSecret | quote }}
{{- end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment