apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: backstage-psql-cr1 # placeholder for 'backstage-psql-<cr-name>'
spec:
  podManagementPolicy: OrderedReady
  replicas: 1
  selector:
    matchLabels:
      rhdh.redhat.com/app: backstage-psql-cr1 # placeholder for 'backstage-psql-<cr-name>'
  serviceName: backstage-psql-cr1-hl # placeholder for 'backstage-psql-<cr-name>-hl'
  template:
    metadata:
      labels:
        rhdh.redhat.com/app: backstage-psql-cr1 # placeholder for 'backstage-psql-<cr-name>'
      name: backstage-db-cr1 # placeholder for 'backstage-psql-<cr-name>'
    spec:
      containers:
        - env:
            - name: POSTGRESQL_PORT_NUMBER
              value: "5432"
            - name: POSTGRESQL_VOLUME_DIR
              value: /var/lib/pgsql/data
            - name: PGDATA
              value: /var/lib/pgsql/data/userdata
          image: quay.io/fedora/postgresql-15:latest # will be replaced with the actual image
          imagePullPolicy: IfNotPresent
          securityContext:
            runAsNonRoot: true
            allowPrivilegeEscalation: false
            seccompProfile:
              type: RuntimeDefault
            capabilities:
              drop:
                - ALL
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - exec pg_isready -U ${POSTGRES_USER} -h 127.0.0.1 -p 5432
            failureThreshold: 6
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          name: postgresql
          ports:
            - containerPort: 5432
              name: tcp-postgresql
              protocol: TCP
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - -e
                - |
                  exec pg_isready -U ${POSTGRES_USER} -h 127.0.0.1 -p 5432
            failureThreshold: 6
            initialDelaySeconds: 5
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          resources:
            requests:
              cpu: 250m
              memory: 256Mi
            limits:
              memory: 1024Mi
          volumeMounts:
            - mountPath: /dev/shm
              name: dshm
            - mountPath: /var/lib/pgsql/data
              name: data
      restartPolicy: Always
      securityContext: {}
      serviceAccount: default
      serviceAccountName: default
      volumes:
        - emptyDir:
            medium: Memory
          name: dshm
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate
  volumeClaimTemplates:
    - apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi