11# *****************************************************************************
2- # Copyright (c) 2024 IBM Corporation and other Contributors.
2+ # Copyright (c) 2025 IBM Corporation and other Contributors.
33#
44# All rights reserved. This program and the accompanying materials
55# are made available under the terms of the Eclipse Public License v1.0
@@ -23,35 +23,20 @@ def cleanup_jobs(k8s_client: client.api_client.ApiClient, label: str):
2323 for cm in cms .items :
2424 cm_ns = cm .metadata .namespace
2525 job_cleanup_group = cm .metadata .labels [label ]
26+ logger .info ("" )
2627 logger .info (f"{ job_cleanup_group } in { cm_ns } " )
28+ logger .info ("-------------------------------" )
2729 try :
2830 current_job_name = cm .data ['current_job_name' ]
31+ logger .info (f"Current Job Name: { current_job_name } " )
2932
3033 # get all Jobs in the same namespace as the configmap that have LABEL: job_cleanup_group
3134 jobs_in_cleanup_group = batch_v1_api .list_namespaced_job (cm_ns , label_selector = f"{ label } ={ job_cleanup_group } " )
3235
33- # sanity checks, abort cleanup of this group if any of these fail
34- # - one of the jobs should be named current_job_name
35- # - all jobs names should have job_cleanup_group as a prefix
36- found_current_job = False
37- for job in jobs_in_cleanup_group .items :
38- job_name = job .metadata .name
39-
40- if job_name == current_job_name :
41- found_current_job = True
42-
43- if not job_name .startswith (job_cleanup_group ):
44- raise Exception (f"Job name { job_name } has unexpected prefix" )
45-
46- if found_current_job :
47- logger .info (f" Found current Job resource: { current_job_name } " )
48- else :
49- raise Exception (f"Could not find current job { current_job_name } " )
50-
5136 for job in jobs_in_cleanup_group .items :
5237 job_name = job .metadata .name
5338 if job_name != current_job_name :
54- logger .info (f" Deleting old Job resource: { job_name } " )
39+ logger .info (f"Deleting old Job resource: { job_name } " )
5540
5641 except Exception as e :
5742 logger .error (f"Skipping { job_cleanup_group } in { cm_ns } : { repr (e )} " )
0 commit comments