# {{- if .Values.database.containerizedDb }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: maestro-db
  namespace: '{{ .Release.Namespace  }}'
spec:
  replicas: 1
  selector:
    matchLabels:
      name: maestro-db
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        name: maestro-db
    spec:
      containers:
      - env:
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              key: db.user
              name: maestro-db
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              key: db.password
              name: maestro-db
        - name: POSTGRES_DB
          valueFrom:
            secretKeyRef:
              key: db.name
              name: maestro-db
        - name: PGDATA
          value: /var/lib/pgsql/data/pgdata
        image: '{{ .Values.database.containerizedDbImage  }}'
        imagePullPolicy: IfNotPresent
        livenessProbe:
          tcpSocket:
            port: 5432
          initialDelaySeconds: 120
          timeoutSeconds: 10
        name: postgresql
        ports:
        - containerPort: 5432
          protocol: TCP
        readinessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - exec /usr/bin/pg_isready -U $POSTGRES_USER -d $POSTGRES_DB -h localhost -p 5432
          initialDelaySeconds: 5
          timeoutSeconds: 1
        securityContext:
          capabilities: {}
          privileged: false
        terminationMessagePath: /dev/termination-log
        volumeMounts:
        - mountPath: /var/lib/pgsql/data
          name: maestro-db-data
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      volumes:
      - name: maestro-db-data
        persistentVolumeClaim:
          claimName: maestro-db
# {{- end }}
