Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of Kubernetes status conditions for jobs?

Is there any resource out there that gives an overview of all the possible status conditions a kubernetes job can have?

I'm wondering because I would like to check, when I run a job if it is already running and if so, exit the new job.

I came across until kubectl get jobs myjob -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep True ; do sleep 1 ; done quite a few times but I want to know if it is running, not if it is already complete. Would prefer not to wait (ha) for kubectl 1.11 wait functionality

like image 631
wesvb Avatar asked Jul 09 '18 15:07

wesvb


People also ask

How can I check my job status in Kubernetes?

Running an example Job It takes around 10s to complete. Check on the status of the Job with kubectl : kubectl describe job pi. kubectl get job pi -o yaml.

What is completed status in Kubernetes?

When a Job completes, no more Pods are created, but the Pods are not deleted either. Keeping them around allows you to still view the logs of completed pods to check for errors, warnings, or other diagnostic output. The job object also remains after it is completed so that you can view its status.


4 Answers

The kubernetes API docs for JobCondition imply that the only type values are “Complete” and “Failed”, and that they may have a ”True” or ”False” status.

In addition to the job status conditions array, you may also find it informative to look at the job status active count, and the startTime and completionTime if you’re just interested in whether it’s finished.

like image 53
David Maze Avatar answered Sep 25 '22 11:09

David Maze


kubectl get jobs <myjob> --namespace <mynamespae> -o jsonpath='{.status.conditions[?(@.type=="Succeeded")].status}'
like image 29
Zhang Chen Avatar answered Sep 26 '22 11:09

Zhang Chen


I believe this can help to get all job statuses for a given selector and after the result can be parsed in bash or CI to wait until some specific statuses:

kubectl get job -n myspace --selector=appName=myapplication -o json | jq -r '.items[] | .metadata.name + ":" + (.status.conditions[] | select(.status == "True") .type + ":" + .status)'
myapplication-job-1558097758:Complete:True
myapplication-job-1558101228:Failed:True

Also here I found another example for bash:

Wait for kubernetes job to complete on either failure/success using command line

By @ruazn2:

until [[ $SECONDS -gt $end ]] || [[ $(kubectl get jobs $job_name -o jsonpath='{.status.conditions[?(@.type=="Failed")].status}') == "True" ]] || [[ $(kubectl get jobs $job_name -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}') == "True" ]]; do
like image 3
kivagant Avatar answered Sep 24 '22 11:09

kivagant


This one has been successfully tested and returns "True" or "False":

kubectl get jobs <myjob> --namespace <mynamespace> -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}'
like image 1
Fabrice Jammes Avatar answered Sep 24 '22 11:09

Fabrice Jammes