Skip to content

Conversation

@haracejacob
Copy link

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

@mbranchnl
Copy link

This issue still occurs, whe solved it by mannualy patching job-wait.py

  pod_list = core_v1.list_namespaced_pod(
      namespace,
      label_selector="job-name==" + name
  )

+++++++
  if not pod_list.items:
      log.warning("No pods found for the job yet, retry")
      time.sleep(5)	
      # Handle this situation as needed
  else:
+++++++
      first_item = pod_list.items[0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants