{{- include "common.values.setup" . -}}
---
apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ include "common.names.fullname" .|lower }}-test-db"
  labels:
{{ include "common.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": test-success
spec:
  template:
    metadata:
      name: "{{ include "common.names.fullname" .|lower }}-test-db"
      labels:
        {{ include "common.labels" . | nindent 8 }}
    spec:
      containers:
      - name: psql
        image: "{{ .Values.dumpBackup.image.repository}}:{{ .Values.dumpBackup.image.tag}}"
        imagePullPolicy: {{ .Values.dumpBackup.image.imagePullPolicy}}
        command: ['sh']
        args:
        - "-ecx"
        - |
          echo ";"|psql

        env:
        - name: PGHOST
          value: {{ include "zalando-postgres-cluster.db" . | quote }}
        - name: PGSSLMODE
          value: require
        - name: PGUSER
          valueFrom:
            secretKeyRef:
              name: {{ include "zalando-postgres-cluster.superuser_secret" . }}
              key: username
        - name: PGPASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ include "zalando-postgres-cluster.superuser_secret" . }}
              key: password
      restartPolicy: Never
