apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  generation: 1
  labels:
    crunchy-pgbouncer: "true"
    name: some-name-pgbouncer
    pg-cluster: some-name
    service-name: some-name-pgbouncer
    vendor: crunchydata
  name: some-name-pgbouncer
spec:
  progressDeadlineSeconds: 600
  replicas: 3
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      crunchy-pgbouncer: "true"
      name: some-name-pgbouncer
      pg-cluster: some-name
      pg-pod-anti-affinity: preferred
      service-name: some-name-pgbouncer
      vendor: crunchydata
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      annotations:
        keep-backups: "false"
        keep-data: "false"
      labels:
        crunchy-pgbouncer: "true"
        name: some-name-pgbouncer
        pg-cluster: some-name
        pg-pod-anti-affinity: preferred
        service-name: some-name-pgbouncer
        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: PG_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: some-name-pgbouncer-secret
            - name: PG_PRIMARY_SERVICE_NAME
          imagePullPolicy: IfNotPresent
          name: pgbouncer
          ports:
            - containerPort: 5432
              name: pgbouncer
              protocol: TCP
          resources:
            limits:
              cpu: "2"
              memory: 512Mi
            requests:
              cpu: "1"
              memory: 128Mi
          securityContext:
            allowPrivilegeEscalation: false
            privileged: false
            readOnlyRootFilesystem: true
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /tmp
              name: tmp
            - mountPath: /pgconf/
              name: pgbouncer-conf
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        runAsNonRoot: true
      serviceAccount: pgo-default
      serviceAccountName: pgo-default
      terminationGracePeriodSeconds: 30
      volumes:
        - emptyDir:
            medium: Memory
            sizeLimit: 1Mi
          name: tmp
        - name: pgbouncer-conf
          projected:
            defaultMode: 420
            sources:
              - configMap:
                  name: some-name-pgbouncer-cm
              - secret:
                  name: some-name-pgbouncer-secret
