{{- $secretName := printf "%s-jwt-key" .Release.Name -}}
{{- $secret := lookup "v1" "Secret" .Release.Namespace $secretName -}}
{{- $key := "" -}}
{{- if $secret -}}
  {{- $key = index $secret.data "GPUSTACK_JWT_SECRET_KEY" | b64dec -}}
{{- else if .Values.server.jwtSecretKey -}}
  {{- $key = .Values.server.jwtSecretKey -}}
{{- else -}}
  {{- $key = randAlphaNum 64 -}}
{{- end -}}
apiVersion: v1
data:
  GPUSTACK_JWT_SECRET_KEY: {{ $key | b64enc }}
kind: Secret
metadata:
  name: {{ $secretName }}
  namespace: {{ .Release.Namespace }}
  labels:
{{ include "chart_labels" . | indent 4 }}
type: Opaque
