When job-wait is executed immediately after job-create, the core_v1.list_namespaced_pod() function sometimes returns an empty array, it cause an IndexError when accessing pod_list.items[0]. This is due to the delay between job creation and pod creation.
To fix this issue, Throwing ApiException(404) when an empty array is returned to execute time.sleep(). And it raise TimeoutError in an error situation.
AS-IS
Traceback (most recent call last):
File "/home1/rundeck/libext/cache/kubernetes-2.0.10/job-wait.py", line 138, in <module>
main()
File "/home1/rundeck/libext/cache/kubernetes-2.0.10/job-wait.py", line 134, in main
wait()
File "/home1/rundeck/libext/cache/kubernetes-2.0.10/job-wait.py", line 60, in wait
first_item = pod_list.items[0]
IndexError: list index out of range
Failed: NonZeroResultCode: Script result code was: 1
TO-BE
WARNING: kubernetes-wait-job: Pod is not ready, status: 404
INFO: kubernetes-wait-job: waiting for log
When
job-wait
is executed immediately afterjob-create
, thecore_v1.list_namespaced_pod()
function sometimes returns an empty array, it cause an IndexError when accessingpod_list.items[0]
. This is due to the delay between job creation and pod creation.To fix this issue, Throwing
ApiException(404)
when an empty array is returned to executetime.sleep()
. And it raiseTimeoutError
in an error situation.AS-IS
TO-BE