apiVersion: batch/v1
kind: Job
metadata:
  name: consume-container-itgtests-job
spec:
  template:
    metadata:
      name: consume-container-itgtests-job
    spec:
      serviceAccountName: itgtests
      containers:
      - name: ibmcase-python
        image: docker-registry.default.svc:5000/itgtests/ibmcase-python:test
        imagePullPolicy: Always
        command: ["bash", "-c" ]
        args:
          - >
              echo "This is the job for consuming containers from the containers Kafka topic" &&
              mkdir ${WORKING_DIR} && cd ${WORKING_DIR} &&
              git clone ${GITHUB_REPO} && cd ${REPO_NAME} && if [ "master" != "${BRANCH}" ]; then git checkout ${BRANCH}; fi &&
              cd ${ITGTESTS_LOCATION} &&
              export PYTHONPATH=${PYTHONPATH}:${WORKING_DIR}/${REPO_NAME}/itg-tests && 
              python -u ConsumeContainers.py ${CONTAINER_ID} ${TOPIC_NAME}
              # The -u flag above is for python to run in unbuffered mode: https://stackoverflow.com/questions/51362213/docker-compose-not-printing-stdout-in-python-app
        env:
        # Your working directory within the container
        - name: WORKING_DIR
          value: "/tmp/github"
        # Github repository containing the integration tests to be executed
        - name: GITHUB_REPO
          value: "https://github.com/ldesrosi/refarch-kc.git"
        # Specific branch for the integration tests
        - name: BRANCH
          value: "master"
        # Name of the repository
        - name: REPO_NAME
          value: "refarch-kc"
        # Location of the integration tests folder within the repository
        - name: ITGTESTS_LOCATION
          value: "itg-tests/ContainersPython"
        # Container ID to be send
        - name: CONTAINER_ID
          value: "regOCP_01"
        # Event Streams topic name which the event will be sent to
        - name: TOPIC_NAME
          value: "itgtest"
        # Event Streams Kafka brokers. You MUST create a configmap in advance with the brokers information:
        # oc create configmap kafka-brokers --from-literal=brokers='<replace with comma-separated list of brokers>' -n <namespace>
        # You can find the list of brokers either in the Event Streams UI or when you login through the CLI: cloudctl es init
        - name: KAFKA_BROKERS
          valueFrom:
            configMapKeyRef:
              name: "kafka-brokers"
              key: brokers
        # Based on this parameter we add the appropriate certificates for when Event Streams is hosted either on ICP or OCP
        - name: KAFKA_ENV
          value: "OCP"
        # Location of your Event Streams pem certificate for ssl connections. You MUST download it in advance.
        # This can be downloaded from the Event Streams UI.
      restartPolicy: Never
  backoffLimit: 0