<p>I use Python kubernetes-client, and want to wait if the job is done:</p>

<pre class="lang-py prettyprint-override"><code>api_instance.create_namespaced_job("default", body, pretty=True)
</code></pre>

<p>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?</p>

<p>I found the solution. You can recognize the job is complete by watching the jobs and observing the events:</p>

<pre class="lang-py prettyprint-override"><code>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"): ....
</code></pre>
