I use Python kubernetes-client, and want to wait if the job is done:
api_instance.create_namespaced_job("default", body, pretty=True)
This call just makes a submit job, it will return the response even though the job is still running. How can I wait for the job to finish?
The only way I managed to do this is calling in the loop:
api_instance.read_namespaced_job_status()
...and check the result status.
You can reach the same by calling kubectl wait
but it's not python. You can clone kubectl sources (in Go) and find how the hell they do it there.
I found the solution. You can recognize the job is complete by watching the jobs and observing the events:
from kubernetes import client, config, watch
config.load_kube_config()
api_client = client.BatchV1Api()
print("INFO: Waiting for event to come up...")
w = watch.Watch()
for event in w.stream(api_client.list_job_for_all_namespaces):
o = event['object']
print(o)
if (o.status.... = "Complete"): ....