{{- if .Values.postgresql.enabled }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "backstage.fullname" . }}-postgres-ca
  labels:
    app: {{ include "backstage.postgresql.fullname" . }}
    release: {{ .Release.Name }}
  annotations:
    "helm.sh/hook": "pre-install"
    "helm.sh/hook-delete-policy": "before-hook-creation"
data:
  {{ .Values.global.postgresql.caFilename }}: |
{{ include "backstage.postgresql.generateCA" . | indent 4}}
{{- else }}
{{- $caConfig := printf "%s-postgres-ca"  (include "backstage.fullname" .) }}
{{- if not ( lookup "v1" "ConfigMap" .Release.Namespace $caConfig ) }}
{{- fail (printf "\n\nPlease create the '%s' configmap with the CA certificate for your existing postgresql: kubectl create configmap %s --from-file=ca.crt" $caConfig $caConfig) }}
{{- end }}
{{- end }}