docker – K8s job .spec.activeDeadlineSeconds vs kubectl wait timeout

I’m building a k8s job container during a GitHub action:

- name: Build job container
  if: startsWith(github.ref,'refs/heads/branch-name’)
  run: docker build -f {path_to_dockerfile} -t job-name:latest . --build-arg ARG=“ARG_VALUE”

And then running a Bash script that runs the job:

kubectl -n$ENV delete jobs/job-name
kustomize build manifests/manifest-name/$ENV | kubectl apply -f - || exit 1
kubectl -n$ENV wait --for=condition=complete job/job-name --timeout=600s

The problem is that the GitHub action succeeds even if the job times out and I see this message printed in the GitHub action step log:

error: timed out waiting for the condition on jobs/job-name

My guess is that it happens because after timeout the bash script doesn’t exit with a non-zero code.

I’ve found the .spec.activeDeadlineSeconds property on a job and it sounds like it does the same in terms of timing out but actually returns a non-zero code in case of failure.

What should I do to fail the GitHub action upon job timeout? Should I modify the kubectl wait or use the .spec.activeDeadlineSeconds property on the job and remove the timeout from the kubectl wait?

Read more here: Source link