{{- if and (not .Values.global.postgresql.existingSecret) (not .Values.postgresql.existingSecret) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "pipelines.fullname" . }}-database
  labels:
    {{- include "pipelines.labels" . | nindent 4 }}
type: Opaque
data:
{{- if .Values.postgresql.enabled }}
  postgresql-password: {{ .Values.postgresql.postgresqlPassword | b64enc | quote }}
  postgresql-url: {{ (printf "postgres://%s:%s@%s-postgresql:%v/%s?sslmode=disable" .Values.postgresql.postgresqlUsername .Values.postgresql.postgresqlPassword .Release.Name .Values.postgresql.service.port .Values.postgresql.postgresqlDatabase) | b64enc }}
{{- else if and (not .Values.postgresql.enabled) (.Values.global.postgresql.ssl) }}
  postgresql-password: {{ tpl .Values.global.postgresql.password . | b64enc | quote }}
  postgresql-url: {{ tpl (printf "postgres://%s:%s@%v:%v/%s?sslmode=require" .Values.global.postgresql.user .Values.global.postgresql.password .Values.global.postgresql.host .Values.global.postgresql.port .Values.global.postgresql.database) . | b64enc }}
{{- else }}
  postgresql-password: {{ tpl .Values.global.postgresql.password . | b64enc | quote }}
  postgresql-url: {{ tpl (printf "postgres://%s:%s@%v:%v/%s?sslmode=disable" .Values.global.postgresql.user .Values.global.postgresql.password .Values.global.postgresql.host .Values.global.postgresql.port .Values.global.postgresql.database) . | b64enc }}
{{- end }}
{{- end }}
