From eb401bec1c2285971036213c3def59a099cfdd7d Mon Sep 17 00:00:00 2001 From: "alvaro.gonzalez" Date: Mon, 16 Dec 2024 08:23:44 +0200 Subject: [PATCH] Improve check by looping the array. It will consider the job complete for 'Complete' and 'SuccessCriteriaMet' types. Still mark Failed jobs as Failed and set the rest as error --- src/tesk_core/job.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/tesk_core/job.py b/src/tesk_core/job.py index a164831..2cffc62 100644 --- a/src/tesk_core/job.py +++ b/src/tesk_core/job.py @@ -46,11 +46,18 @@ def run_to_completion(self, poll_interval, check_cancelled, pod_timeout): def get_status(self, is_all_pods_runnning): job = self.bv1.read_namespaced_job(self.name, self.namespace) try: - if job.status.conditions[0].type == 'Complete' and job.status.conditions[0].status: - self.status = 'Complete' - elif job.status.conditions[0].type == 'Failed' and job.status.conditions[0].status: - self.status = 'Failed' - else: + # Loops around the status conditions array, and looks for 'Complete', 'Failed' or + # 'SuccessCriteriaMet'. If none of these are found, the Job is marked as 'Error' + for condition in job.status.conditions: + if condition.type == 'Complete' and condition.status: + self.status = 'Complete' + break + if condition.type == 'Failed' and condition.status: + self.status = 'Failed' + break + if condition.type == 'SuccessCriteriaMet' and condition.status: + self.status = 'Complete' + break self.status = 'Error' except TypeError: # The condition is not initialized, so it is not complete yet, wait for it self.status = 'Running'