{{- if (not .Values.airflow.auth.existingSecret) -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "airflow.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "airflow.name" . }}
    helm.sh/chart: {{ include "airflow.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
type: Opaque
data:
  {{- if .Values.airflow.auth.password }}
  airflow-password: {{ .Values.airflow.auth.password | b64enc | quote }}
  {{ else if (not .Values.airflow.auth.forcePassword) }}
  airflow-password: {{ randAlphaNum 10 | b64enc | quote }}
  {{ else }}
  airflow-password: {{ required "An Airflow Password is required!" .Values.airflow.auth.password }}
  {{- end }}
  {{- if .Values.airflow.auth.fernetKey }}
  airflow-fernetKey: {{ .Values.airflow.auth.fernetKey | b64enc | quote }}
  {{ else if (not .Values.airflow.auth.forcePassword) }}
  airflow-fernetKey: {{ randAlphaNum 32 | b64enc | b64enc | quote }}
  {{ else }}
  airflow-fernetKey: {{ required "An Airflow Fernet Key is required!" .Values.airflow.auth.fernetKey }}
  {{- end }}
{{- end }}