apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: opa-db-statefulset
  namespace: hm-opa
spec:
  serviceName: "opa-db-service"
  replicas: 1
  selector:
    matchLabels:
      component: opa-db
  template:
    metadata:
      labels:
        component: opa-db
    spec:
      containers:
        - name: opa-db
          image: postgres:13.3-alpine
          env:
            - name: PGDATA
              valueFrom:
                configMapKeyRef:
                  name: opa-db-configmap
                  key: pgdata
            - name: POSTGRES_DB
              valueFrom:
                configMapKeyRef:
                  name: opa-db-configmap
                  key: postgres_db
            - name: POSTGRES_USER
              valueFrom:
                configMapKeyRef:
                  name: opa-db-configmap
                  key: postgres_user
            - name: POSTGRES_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: opa-db-configmap
                  key: postgres_password
          ports:
            - name: postgres
              protocol: TCP
              containerPort: 5432
          volumeMounts:
            - name: opa-db-volume
              mountPath: /var/lib/postgresql/data
            - name: opa-db-sql-volume
              mountPath: /docker-entrypoint-initdb.d
      volumes:
        - name: opa-db-sql-volume
          persistentVolumeClaim:
            claimName: opa-db-sql-pvc
  volumeClaimTemplates:
    - metadata:
        name: opa-db-volume
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 1Gi
