apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  generation: 1
  labels:
    crunchy-pgha-scope: some-name
    deployment-name: some-name-repl3
    name: some-name-replica
    pg-cluster: some-name
    pgo-pg-database: "true"
    pgo-version: 1.2.0
    service-name: some-name-replica
    vendor: crunchydata
  name: some-name-repl3
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      deployment-name: some-name-repl3
      pg-cluster: some-name
      pgo-pg-database: "true"
      vendor: crunchydata
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      annotations:
        keep-backups: "false"
        keep-data: "false"
      labels:
        crunchy-pgha-scope: some-name
        deployment-name: some-name-repl3
        name: some-name-replica
        pg-cluster: some-name
        pg-pod-anti-affinity: preferred
        pgo-pg-database: "true"
        pgo-version: 1.2.0
        vendor: crunchydata
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: vendor
                      operator: In
                      values:
                        - crunchydata
                    - key: pg-pod-anti-affinity
                      operator: Exists
                    - key: pg-cluster
                      operator: In
                      values:
                        - some-name
                topologyKey: kubernetes.io/hostname
              weight: 1
      containers:
        - env:
            - name: MODE
              value: postgres
            - name: PGHA_PG_PORT
              value: "5432"
            - name: PGHA_USER
              value: postgres
            - name: PATRONI_POSTGRESQL_DATA_DIR
              value: /pgdata/some-name-repl3
            - name: PGBACKREST_STANZA
              value: db
            - name: PGBACKREST_REPO1_HOST
              value: some-name-backrest-shared-repo
            - name: BACKREST_SKIP_CREATE_STANZA
              value: "true"
            - name: PGHA_PGBACKREST
              value: "true"
            - name: PGBACKREST_REPO1_PATH
              value: /backrestrepo/some-name-backrest-shared-repo
            - name: PGBACKREST_DB_PATH
              value: /pgdata/some-name-repl3
            - name: ENABLE_SSHD
              value: "true"
            - name: PGBACKREST_LOG_PATH
              value: /tmp
            - name: PGBACKREST_PG1_SOCKET_PATH
              value: /tmp
            - name: PGBACKREST_PG1_PORT
              value: "5432"
            - name: PGBACKREST_REPO1_TYPE
              value: posix
            - name: PGHA_PGBACKREST_LOCAL_S3_STORAGE
              value: "false"
            - name: PGHA_PGBACKREST_LOCAL_GCS_STORAGE
              value: "false"
            - name: PGHA_DATABASE
              value: some-name
            - name: PGHA_REPLICA_REINIT_ON_START_FAIL
              value: "true"
            - name: PGHA_SYNC_REPLICATION
              value: "false"
            - name: PGHA_TLS_ENABLED
              value: "false"
            - name: PGHA_TLS_ONLY
              value: "false"
            - name: PGHA_PASSWORD_TYPE
            - name: PGHA_STANDBY
              value: "false"
            - name: PATRONI_KUBERNETES_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: PATRONI_KUBERNETES_SCOPE_LABEL
              value: crunchy-pgha-scope
            - name: PATRONI_SCOPE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.labels['crunchy-pgha-scope']
            - name: PATRONI_KUBERNETES_LABELS
              value: '{vendor: "crunchydata"}'
            - name: PATRONI_LOG_LEVEL
              value: INFO
            - name: PGHOST
              value: /tmp
            - name: LD_PRELOAD
              value: /usr/lib64/libnss_wrapper.so
            - name: NSS_WRAPPER_PASSWD
              value: /tmp/nss_wrapper/postgres/passwd
            - name: NSS_WRAPPER_GROUP
              value: /tmp/nss_wrapper/postgres/group
          imagePullPolicy: IfNotPresent
          livenessProbe:
            exec:
              command:
                - /opt/crunchy/bin/postgres-ha/health/pgha-liveness.sh
            failureThreshold: 3
            initialDelaySeconds: 30
            periodSeconds: 15
            successThreshold: 1
            timeoutSeconds: 10
          name: database
          ports:
            - containerPort: 5432
              name: postgres
              protocol: TCP
            - containerPort: 8009
              name: patroni
              protocol: TCP
          readinessProbe:
            exec:
              command:
                - /opt/crunchy/bin/postgres-ha/health/pgha-readiness.sh
            failureThreshold: 3
            initialDelaySeconds: 15
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          resources:
            requests:
              memory: 128Mi
          securityContext:
            allowPrivilegeEscalation: false
            privileged: false
            readOnlyRootFilesystem: true
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /pgdata
              name: pgdata
            - mountPath: /pgconf/pguser
              name: user-volume
            - mountPath: /pgconf/pgreplicator
              name: primary-volume
            - mountPath: /pgconf/pgsuper
              name: root-volume
            - mountPath: /sshd
              name: sshd
              readOnly: true
            - mountPath: /etc/ssh
              name: ssh-config
              readOnly: true
            - mountPath: /pgconf
              name: pgconf-volume
            - mountPath: /dev/shm
              name: dshm
            - mountPath: /etc/pgbackrest/conf.d
              name: pgbackrest-config
            - mountPath: /etc/podinfo
              name: podinfo
            - mountPath: /tmp
              name: tmp
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        fsGroup: 26
        supplementalGroups:
          - 1001
      serviceAccount: pgo-pg
      serviceAccountName: pgo-pg
      terminationGracePeriodSeconds: 30
      volumes:
        - name: pgdata
          persistentVolumeClaim:
            claimName: some-name-repl3
        - name: user-volume
          secret:
            defaultMode: 420
            secretName: some-name-some-name-secret
        - name: primary-volume
          secret:
            defaultMode: 420
            secretName: some-name-primaryuser-secret
        - name: sshd
          secret:
            defaultMode: 420
            secretName: some-name-backrest-repo-config
        - name: ssh-config
          secret:
            defaultMode: 420
            items:
              - key: config
                path: ssh_config
            secretName: some-name-backrest-repo-config
        - name: root-volume
          secret:
            defaultMode: 420
            secretName: some-name-postgres-secret
        - emptyDir:
            medium: Memory
            sizeLimit: 64Mi
          name: report
        - emptyDir:
            medium: Memory
          name: dshm
        - emptyDir:
            medium: Memory
            sizeLimit: 16Mi
          name: tmp
        - name: pgbackrest-config
          projected:
            defaultMode: 420
            sources:
              - configMap:
                  name: some-name-config-backrest
                  optional: true
              - secret:
                  name: some-name-config-backrest
                  optional: true
        - name: pgconf-volume
          projected:
            defaultMode: 420
            sources:
              - configMap:
                  name: some-name-pgha-config
                  optional: true
        - downwardAPI:
            defaultMode: 420
            items:
              - path: cpu_limit
                resourceFieldRef:
                  containerName: database
                  divisor: 1m
                  resource: limits.cpu
              - path: cpu_request
                resourceFieldRef:
                  containerName: database
                  divisor: 1m
                  resource: requests.cpu
              - path: mem_limit
                resourceFieldRef:
                  containerName: database
                  divisor: "0"
                  resource: limits.memory
              - path: mem_request
                resourceFieldRef:
                  containerName: database
                  divisor: "0"
                  resource: requests.memory
              - fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.labels
                path: labels
              - fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.annotations
                path: annotations
          name: podinfo
