apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: noobaa-db-pg
  labels:
    app: noobaa
spec:
  replicas: 1
  selector:
    matchLabels:
      noobaa-db: noobaa
  serviceName: noobaa-db-pg
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: noobaa
        noobaa-db: postgres
    spec:
      serviceAccountName: noobaa
      initContainers:
      #----------------#
      # INIT CONTAINER #
      #----------------#
      - name: init
        image: NOOBAA_CORE_IMAGE
        command:
        - /noobaa_init_files/noobaa_init.sh
        - init_postgres
        resources:
          requests:
            cpu: "500m"
            memory: "500Mi"
          limits:
            cpu: "500m"
            memory: "500Mi"
        volumeMounts:
        - name: db
          mountPath: /var/lib/pgsql
      containers:
      #--------------------#
      # Postgres CONTAINER #
      #--------------------#
      - name: db
        image: NOOBAA_DB_IMAGE
        env:
          - name: POSTGRESQL_DATABASE
            value: nbcore
          - name: POSTGRESQL_USER
          - name: POSTGRESQL_PASSWORD
        imagePullPolicy: "IfNotPresent"
        ports:
          - containerPort: 5432
        resources:
          requests:
            cpu: "2"
            memory: "4Gi"
          limits:
            cpu: "2"
            memory: "4Gi"
        volumeMounts:
          - name: db
            mountPath: /var/lib/pgsql
          - name: noobaa-postgres-config-volume
            mountPath: /opt/app-root/src/postgresql-cfg
      volumes:
      - name: noobaa-postgres-config-volume
        configMap:
          name: noobaa-postgres-config
      securityContext: 
        runAsUser: 10001
        runAsGroup: 0
  volumeClaimTemplates:
    - metadata:
        name: db
        labels:
          app: noobaa
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 50Gi
