From 7bb08512177471eb9a6245479478dd989f8a76c6 Mon Sep 17 00:00:00 2001 From: Prabha <58968096+zidhumenon@users.noreply.github.com> Date: Sun, 18 Apr 2021 16:14:24 +0530 Subject: [PATCH] Fix issue #1395 create_job function was not printing the current status of the job. Modified the create_job function to call read_namespaced_job_status in order to get the current job status --- examples/job_crud.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/job_crud.py b/examples/job_crud.py index b18b152d4..e25f330d6 100644 --- a/examples/job_crud.py +++ b/examples/job_crud.py @@ -20,6 +20,8 @@ from os import path import yaml +from time import sleep + from kubernetes import client, config JOB_NAME = "pi" @@ -53,7 +55,16 @@ def create_job(api_instance, job): api_response = api_instance.create_namespaced_job( body=job, namespace="default") - print("Job created. status='%s'" % str(api_response.status)) + # Need to wait for a second for the job status to update + sleep(1) + print("Job created. status='%s'" % str(get_job_status(api_instance))) + + +def get_job_status(api_instance): + api_response = api_instance.read_namespaced_job_status( + name=JOB_NAME, + namespace="default") + return api_response.status def update_job(api_instance, job):