---
apiVersion: batch/v1
kind: Job
metadata:
  generateName: postgres-liveness-
  namespace: e2e
spec:
  template:
    metadata:
      name: postgres-liveness
      namespace: e2e
      labels:
        # label used to track percona liveness job by ci-tool/test
        liveness: postgres-liveness

        # label used for mass-liveness check upon infra-chaos
        infra-aid: liveness

    spec:
      serviceAccountName: e2e
      restartPolicy: Never

      #nodeSelector:
      #  kubernetes.io/hostname:

      tolerations:
        - key: "infra-aid"
          value: "observer"
          operator: "Equal"
          effect: "NoSchedule"
 
      containers:
      - name: ansibletest
        image: openebs/ansible-runner:ci
        imagePullPolicy: IfNotPresent
        env: 
          - name: ANSIBLE_STDOUT_CALLBACK
            value: default

          - name: MY_POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name

        command: ["/bin/bash"]
        args: ["-c", "ansible-playbook ./apps/crunchy-postgres/liveness/test.yml -i /etc/ansible/hosts -v; exit 0"]

      - name: postgres-liveness  
        image: openebs/tests-postgresql-client
        env:
          # Time period (in sec) b/w retries for DB init check
          - name: INIT_WAIT_DELAY
            value: "30"
 
          # No of retries for DB init check
          - name: INIT_RETRY_COUNT
            value: "10"

          # Time period (in sec) b/w liveness checks
          - name: LIVENESS_PERIOD_SECONDS
            value: "10"

          # Time period (in sec) b/w retries for db_connect failure            
          - name: LIVENESS_TIMEOUT_SECONDS
            value: "10"

          # No of retries after a db_connect failure before declaring liveness fail
          - name: LIVENESS_RETRY_COUNT
            value: "6"

          # Namespace in Which Postgres is Running
          - name: NAMESPACE
            value: app-pgres-ns

            # Service Name of postgres
          - name: SERVICE_NAME
            value: pgset

            #Database name of postgres
          - name: DATABASE
            value: userdb

            # Usr name of Postgres
          - name: USER
            value: testuser

            # Password for the Postgres
          - name: PASSWORD
            value: password

            # Port on which application is listening
          - name: PORT
            value: "5432"

        command: ["/bin/bash"]
        args: ["-c", "python ./liveness.py ; exit 0"]
