apiVersion: v1
kind: Secret
metadata:
  name: grafana-admin-password
  labels:
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
{{- $existingSecret := lookup "v1" "Secret" .Release.Namespace "grafana-admin-password" }}
  {{- if $existingSecret }}
  user: {{ index $existingSecret.data "user" }}
  password: {{ index $existingSecret.data "password" }}
  {{- else }}
  user: {{ b64enc "admin" }}
  password: {{ randAlphaNum 32 | b64enc }}
  {{- end }}
