apiVersion: apps/v1
kind: Deployment
metadata:
  name: pgplus
  labels:
    role: db
spec:
  replicas: 3
  selector:
    matchLabels:
      role: db
  template:
    metadata:
      labels:
        role: db
        # set to "1" (e.g. is_standby: "1") if PostgreSQL should be a standby
        # Controls env variable: POSTGRES_IS_STANDBY
        is_standby: ""
        # set to "1" (e.g. restore: "1") if PostgreSQL should restore base-backup
        # Controls env variable: POSTGRES_RESTORE
        restore: ""
        # set to non-empty string (e.g. done: "1") once appropriate labels are set on each Pod
        done: ""
    spec:
      containers:
      - name: pgplus
        image: dustymugs/pgplus:12-3.0
        imagePullPolicy: Always
        resources:
          limits:
            memory: "1Gi"
          requests:
            memory: "512Mi"
        env:
        - name: POSTGRES_MASTER_DNS_NAME # domain name for master PostgreSQL pod
          valueFrom:
            configMapKeyRef:
              name: pgplus
              key: postgres.master_dns_name
              optional: true
        # non-empty string instructs container to download latest base-backup
        # overwritten by the pod label `restore`
        - name: POSTGRES_RESTORE
          valueFrom:
            configMapKeyRef:
              name: pgplus
              key: postgres.restore
              optional: true
        # non-empty string instructs container to touch $PGDATA/standby.signal
        # overwritten by the pod label `is_standby`
        - name: POSTGRES_IS_STANDBY
          valueFrom:
            configMapKeyRef:
              name: pgplus
              key: postgres.is_standby
              optional: true
        - name: POSTGRES_INITDB_ARGS
          valueFrom:
            configMapKeyRef:
              name: pgplus
              key: postgres.initdb_args
              optional: true
        - name: POSTGRES_ARCHIVE_MODE # (on|off)
          valueFrom:
            configMapKeyRef:
              name: pgplus
              key: postgres.archive_mode
              optional: true
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: pgplus
              key: postgres.user
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: pgplus
              key: postgres.password
        - name: POSTGRES_PRIMARY_CONNINFO
          valueFrom:
            secretKeyRef:
              name: pgplus
              key: postgres.primary_conninfo
              optional: true
        - name: PGBOUNCER_POOL_MODE # (session, transaction, statement)
          valueFrom:
            configMapKeyRef:
              name: pgplus
              key: pgbouncer.pool_mode
              optional: true
        - name: AWS_ACCESS_KEY_ID
          valueFrom:
            secretKeyRef:
              name: pgplus
              key: walg.access_key
        - name: AWS_SECRET_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: pgplus
              key: walg.secret_key
        # required for non-AWS endpoints e.g. https://sfo2.digitaloceanspaces.com/
        - name: AWS_ENDPOINT
          valueFrom:
            configMapKeyRef:
              name: pgplus
              key: walg.aws_endpoint
        - name: WALG_S3_PREFIX # e.g. s3://bucket/path/to/files
          valueFrom:
            configMapKeyRef:
              name: pgplus
              key: walg.s3_prefix
        ports:
        - containerPort: 5432
        - containerPort: 6432
        volumeMounts:
          - name: podinfo
            mountPath: /etc/podinfo
        #command: ["/pgplus-docker-entrypoint.sh"]
        #args: ["postgres"]
      volumes:
        - name: podinfo
          downwardAPI:
            items:
              - path: "labels"
                fieldRef:
                  fieldPath: metadata.labels
