{{- $secret := (lookup "v1" "Secret" .Release.Namespace (printf "%s-secret" .Release.Name)) }}

{{- $appKeyValue := (printf "%s%s" "base64:" (encryptAES (randAlpha 32) "plaintext")) }}
{{- if $secret }}
{{- $appKeyValue = index $secret.data "APP_KEY" }}
{{- end -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ .Release.Name }}-secret
type: Opaque
stringData:
  DB_USERNAME: {{ .Values.mysql.auth.username | quote }}
  DB_PASSWORD: {{ .Values.mysql.auth.password | quote }}
  APP_KEY: {{ .Values.app.key | default $appKeyValue | quote }}
