apiVersion: batch/v1
kind: Job
metadata:
  name: test-app-job-more-than-one-container
  namespace: default
spec:
  backoffLimit: 1
  template:
    metadata:
      annotations:
        ovai.asaintsever.org/inject: "true"
        ovai.asaintsever.org/mode: "job"
      labels:
        com.ovai.application: test
        com.ovai.service: test-app-svc
    spec:
      restartPolicy: Never
      # custom serviceAccountName with role allowing to perform GET on pods (needed to poll for job's pod status)
      serviceAccountName: job-sa
      containers:
        - name: test-app-job-more-than-one-container-1
          image: busybox:1.28
          command:
            - "sh"
            - "-c"
            - |
              set -e
              while true; do
                echo "Wait for secrets file before running job..."
                if [ -f "/opt/ovai/secrets/secrets.properties" ]; then
                  echo "Secrets available"
                  break
                fi
                sleep 2
              done
              echo "Job started"
              echo "I am a job... still working - 1"
              cat /opt/ovai/secrets/secrets.properties
              sleep 5
              echo "I am a job... still working - 2"
              cat /opt/ovai/secrets/secrets.properties
              sleep 5
              echo "I am a job... still working - 3"
              cat /opt/ovai/secrets/secrets.properties
              sleep 5
              echo "I am a job... still working - 4"
              cat /opt/ovai/secrets/secrets.properties
              sleep 5
              echo "I am a job... still working - 5"
              cat /opt/ovai/secrets/secrets.properties
              echo "Job stopped"
          volumeMounts:
            - name: secrets
              mountPath: /opt/ovai/secrets
        - name: test-app-job-more-than-one-container-2
          image: busybox:1.28
          command:
            - "sh"
            - "-c"
            - |
              set -e
              while true; do
                echo "Wait for secrets file before running job..."
                if [ -f "/opt/ovai/secrets/secrets.properties" ]; then
                  echo "Secrets available"
                  break
                fi
                sleep 2
              done
              echo "Job started"
              echo "I am a job... still working - 1"
              cat /opt/ovai/secrets/secrets.properties
              sleep 5
              echo "I am a job... still working - 2"
              cat /opt/ovai/secrets/secrets.properties
              sleep 5
              echo "I am a job... still working - 3"
              cat /opt/ovai/secrets/secrets.properties
              sleep 5
              echo "I am a job... still working - 4"
              cat /opt/ovai/secrets/secrets.properties
              sleep 5
              echo "I am a job... still working - 5"
              cat /opt/ovai/secrets/secrets.properties
              echo "Job stopped"
          volumeMounts:
            - name: secrets
              mountPath: /opt/ovai/secrets
      volumes:
        - name: secrets
          emptyDir:
            medium: Memory