apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: {{ template "postgres-operator.name" . }}
    helm.sh/chart: {{ template "postgres-operator.chart" . }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
  name: {{ template "postgres-operator.fullname" . }}
  namespace: {{ .Release.Namespace }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ template "postgres-operator.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      annotations:
      {{- if eq .Values.configTarget "ConfigMap" }}
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
      {{- else }}
        checksum/config: {{ include (print $.Template.BasePath "/operatorconfiguration.yaml") . | sha256sum }}
      {{- end }}
    {{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
    {{- end }}
      labels:
        app.kubernetes.io/name: {{ template "postgres-operator.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
      {{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | indent 8 }}
      {{- end }}
    spec:
      serviceAccountName: {{ include "postgres-operator.serviceAccountName" . }}
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        env:
      {{- if .Values.enableJsonLogging }}
        - name: ENABLE_JSON_LOGGING
          value: "true"
      {{- end }}
      {{- if eq .Values.configTarget "ConfigMap" }}
        - name: CONFIG_MAP_NAME
          value: {{ template "postgres-operator.fullname" . }}
      {{- else }}
        - name: POSTGRES_OPERATOR_CONFIGURATION_OBJECT
          value: {{ template "postgres-operator.fullname" . }}
      {{- end }}
      {{- if .Values.controllerID.create }}
        - name: CONTROLLER_ID
          value: {{ template "postgres-operator.controllerID" . }}
      {{- end }}
        resources:
{{ toYaml .Values.resources | indent 10 }}
        securityContext:
{{ toYaml .Values.securityContext | indent 10 }}
        {{- if .Values.readinessProbe }}
        readinessProbe:
          httpGet:
            path: /readyz
            port: {{ .Values.configLoggingRestApi.api_port }}
          initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
        {{- end }}
      {{- if .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 8 }}
      {{- end }}
      affinity:
{{ toYaml .Values.affinity | indent 8 }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
    {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName }}
    {{- end }}
