{{- if (include "mariadb.createSecret" .) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "common.names.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  {{- if not (empty .Values.auth.rootPassword) }}
  mariadb-root-password: {{ .Values.auth.rootPassword | b64enc | quote }}
  {{- else if (not .Values.auth.forcePassword) }}
  mariadb-root-password: {{ randAlphaNum 10 | b64enc | quote }}
  {{- else }}
  mariadb-root-password: {{ required "A MariaDB Root Password is required!" .Values.auth.rootPassword }}
  {{- end }}
  {{- if and (not (empty .Values.auth.username)) (not (empty .Values.auth.password)) }}
  mariadb-password: {{ .Values.auth.password | b64enc | quote }}
  {{- else if (not .Values.auth.forcePassword) }}
  mariadb-password: {{ randAlphaNum 10 | b64enc | quote }}
  {{- else }}
  mariadb-password: {{ required "A MariaDB Database Password is required!" .Values.auth.password }}
  {{- end }}
  {{- if eq .Values.architecture "replication" }}
  {{- if not (empty .Values.auth.replicationPassword) }}
  mariadb-replication-password: {{ .Values.auth.replicationPassword | b64enc | quote }}
  {{- else if (not .Values.auth.forcePassword) }}
  mariadb-replication-password: {{ randAlphaNum 10 | b64enc | quote }}
  {{- else }}
  mariadb-replication-password: {{ required "A MariaDB Replication Password is required!" .Values.auth.replicationPassword }}
  {{- end }}
  {{- end }}
{{- end }}
