{{- $secretName := printf "%s-flask-server-secret-key" (include "mlflow.fullname" .) }}
{{- $flaskServerSecretKey := ternary .Values.flaskServerSecretKey (include "mlflow.generateRandomHex" 32) (ne .Values.flaskServerSecretKey "") }}
{{- if not (lookup "v1" "Secret" .Release.Namespace $secretName) }}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{ $secretName }}
  namespace: {{ .Release.Namespace }}
  labels:
    app: {{ include "mlflow.name" . }}
    chart: {{ include "mlflow.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  annotations:
    "helm.sh/hook": "pre-install,pre-upgrade"
    "helm.sh/hook-delete-policy": "before-hook-creation"
type: Opaque
data:
  MLFLOW_FLASK_SERVER_SECRET_KEY: {{ $flaskServerSecretKey | b64enc | quote }}
{{- end }}
