# Copyright (C) 2021  Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: aasdb-deployment
  namespace: isecl
  labels:
    app: aasdb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: aasdb
  template:
    metadata:
      labels:
        app: aasdb
    spec:
      securityContext:
        fsGroup: 1001
      containers:
        - name: aasdb
          image: postgres:11.7
          imagePullPolicy: Always
          securityContext:
            runAsUser: 1001
            runAsGroup: 1001
          args:
            - -c
            - hba_file=/etc/postgresql/config/pg_hba.conf
            - -c
            - config_file=/etc/postgresql/config/postgresql.conf
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              value: aasdb
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: aas-db-credentials
                  key: AAS_DB_USERNAME
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: aas-db-credentials
                  key: AAS_DB_PASSWORD
            - name: PGDATA
              value: /var/lib/postgresql/data/pgdata
          volumeMounts:
            - name: aas-db-config
              mountPath: /etc/postgresql/config/
              readOnly: true
            - name: aas-db-certs
              mountPath: /etc/postgresql/secrets/
              readOnly: true
            - name: aas-db-data
              mountPath: /var/lib/postgresql/data/pgdata
      volumes:
        - name: aas-db-config
          configMap:
            name: aas-db-config
            defaultMode: 0640
        - name: aas-db-certs
          secret:
            secretName: aas-db-certs
            defaultMode: 0640
        - name: aas-db-data
          persistentVolumeClaim:
            claimName: aas-db-pvc
