{{- if (not .Values.existingSecret) -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "mysql.fullname" . }}
  labels: {{- include "mysql.labels" . | nindent 4 }}
type: Opaque
data:
  {{- if .Values.root.password }}
  mysql-root-password: {{ .Values.root.password | b64enc | quote }}
  {{- else if (not .Values.root.forcePassword) }}
  mysql-root-password: {{ randAlphaNum 10 | b64enc | quote }}
  {{ else }}
  mysql-root-password: {{ required "A MySQL Root Password is required!" .Values.root.password }}
  {{- end }}
  {{- if .Values.db.user }}
  {{- if .Values.db.password }}
  mysql-password: {{ .Values.db.password | b64enc | quote }}
  {{- else if (not .Values.db.forcePassword) }}
  mysql-password: {{ randAlphaNum 10 | b64enc | quote }}
  {{- else }}
  mysql-password: {{ required "A MySQL Database Password is required!" .Values.db.password }}
  {{- end }}
  {{- end }}
  {{- if .Values.replication.enabled }}
  {{- if .Values.replication.password }}
  mysql-replication-password: {{ .Values.replication.password | b64enc | quote }}
  {{- else if (not .Values.replication.forcePassword) }}
  mysql-replication-password: {{ randAlphaNum 10 | b64enc | quote }}
  {{- else }}
  mysql-replication-password: {{ required "A MySQL Replication Password is required!" .Values.replication.password }}
  {{- end }}
  {{- end }}
{{- end }}
