{{- if (not .Values.auth.existingSecret) -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "common.names.fullname" . }}
  namespace: {{ .Release.Namespace | quote }}
  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:
  admin-user-password: {{ ternary (randAlphaNum 10) .Values.auth.admin.password (empty .Values.auth.admin.password) | b64enc | quote }}
  admin-user-token: {{ ternary (randAlphaNum 20) .Values.auth.admin.token (empty .Values.auth.admin.token) | b64enc | quote }}
  {{- if .Values.auth.user.username }}
  user-password: {{ ternary (randAlphaNum 10) .Values.auth.user.password (empty .Values.auth.user.password) | b64enc | quote }}
  {{- end }}
  {{- if .Values.auth.readUser.username }}
  read-user-password: {{ ternary (randAlphaNum 10) .Values.auth.readUser.password (empty .Values.auth.readUser.password) | b64enc | quote }}
  {{- end }}
  {{- if .Values.auth.writeUser.username }}
  write-user-password: {{ ternary (randAlphaNum 10) .Values.auth.writeUser.password (empty .Values.auth.writeUser.password) | b64enc | quote }}
  {{- end }}
{{- end }}
