{{- $secret := (lookup "v1" "Secret" .Values.namespace .Values.postgresCluster.secrets.citusSecrets.rolesSecret ) -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ .Values.postgresCluster.secrets.citusSecrets.rolesSecret }}
type: Opaque
data:
  {{- if not $secret }}
  {{- range $key, $value := .Values.postgresCluster.secrets.citusRolesSecrets }}
  {{ $key }}Pass: {{ randAlphaNum 12 | b64enc | quote }}
  {{- end }}
  {{- else }}
  {{- range $key, $value := .Values.postgresCluster.secrets.citusRolesSecrets }}
    {{- $keyPass := (print $key "Pass") }}
  {{- if hasKey $secret.data $keyPass }}
  {{ $key }}Pass: {{ index $secret.data $keyPass }}
  {{- else }}
  {{ $key }}Pass: {{ randAlphaNum 12 | b64enc | quote }}
  {{- end }}
  {{- end }}
  {{- end }}
  {{- range $key, $value := .Values.postgresCluster.secrets.citusRolesSecrets }}
  {{ $key }}Name: {{ $value | b64enc }}
  {{- end }}
