{{- if .Values.mysql.customDatabases }}
apiVersion: v1
kind: Secret
metadata:
  name: deploykf-mysql-custom-databases
  labels:
    helm.sh/chart: {{ include "deploykf-mysql.labels.chart" . }}
    app.kubernetes.io/name: {{ include "deploykf-mysql.labels.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/component: mysql
data:
  {{- range $db_index, $database := .Values.mysql.customDatabases }}
  {{- range $owner_index, $owner := $database.grantAllPrivileges }}
  {{ printf "%d_owner_%d_username" $db_index $owner_index | quote }}: {{ $owner.username | b64enc | quote }}
  {{ printf "%d_owner_%d_hostname" $db_index $owner_index | quote }}: {{ $owner.hostname | b64enc | quote }}
  {{- end }}
  {{- end }}
{{- end }}