{{ if .Values.postgresql.enabled }}
{{- $password := (randAlpha 16) | b64enc | quote }}
{{- $postgresPassword := (randAlpha 16) | b64enc | quote }}
{{- $secret := (lookup "v1" "Secret" .Release.Namespace .Values.postgresql.auth.existingSecret) }}
{{- if $secret }}
{{- $password = index $secret.data "password" }}
{{- $postgresPassword = index $secret.data "postgres-password" }}
{{- end }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ .Values.postgresql.auth.existingSecret }}
  labels:
    {{- include "defguard.labels" . | nindent 4 }}
type: Opaque
data:
  password: {{ $password }}
  postgres-password: {{ $postgresPassword }}
{{- end }}
