{{- if or (and (eq .Values.database.type "mysql") .Values.database.mysql.enabled (not .Values.database.mysql.auth.existingSecret)) (and (eq .Values.database.type "postgres") .Values.database.postgres.enabled (not .Values.database.postgres.auth.existingSecret)) (and (eq .Values.database.type "external") .Values.database.external.enabled (not .Values.database.external.existingSecret)) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "katib.database.secretName" . }}
  namespace: {{ include "katib.namespace" . }}
  {{- if not .Values.global.kustomizeMode.omitLabelsFromSecrets }}
  labels:
    {{- include "katib.labels" . | nindent 4 }}
  {{- end }}
type: Opaque
data:
  {{- if eq .Values.database.type "mysql" }}
  {{- if .Values.database.mysql.auth.rootPassword }}
  MYSQL_ROOT_PASSWORD: {{ .Values.database.mysql.auth.rootPassword | b64enc }}
  {{- else }}
  MYSQL_ROOT_PASSWORD: {{ "dGVzdA==" }}
  {{- end }}
  {{- if not .Values.global.kustomizeMode.omitExtraSecretFields }}
  {{- if .Values.database.mysql.auth.password }}
  MYSQL_PASSWORD: {{ .Values.database.mysql.auth.password | b64enc }}
  {{- else }}
  MYSQL_PASSWORD: {{ randAlphaNum 16 | b64enc }}
  {{- end }}
  MYSQL_USER: {{ .Values.database.mysql.auth.username | b64enc }}
  MYSQL_DATABASE: {{ .Values.database.mysql.auth.database | b64enc }}
  {{- end }}
  {{- else if eq .Values.database.type "postgres" }}
  {{- if .Values.database.postgres.auth.password }}
  POSTGRES_PASSWORD: {{ .Values.database.postgres.auth.password | b64enc }}
  {{- else }}
  POSTGRES_PASSWORD: {{ randAlphaNum 16 | b64enc }}
  {{- end }}
  POSTGRES_USER: {{ .Values.database.postgres.auth.username | b64enc }}
  POSTGRES_DB: {{ .Values.database.postgres.auth.database | b64enc }}
  {{- else if eq .Values.database.type "external" }}
  KATIB_MYSQL_DB_DATABASE: {{ "" | quote }}
  KATIB_MYSQL_DB_HOST: {{ "" | quote }}
  KATIB_MYSQL_DB_PORT: {{ "" | quote }}
  DB_USER: {{ "" | quote }}
  DB_PASSWORD: {{ "" | quote }}
  {{- end }}
{{- end }}