in dags/map_reproducibility/utils/common_utils.py [0:0]
def cleanup_cmds():
cleanup = (
"kubectl config set-context --current --namespace=default ",
# Attempt Helm uninstall first, continue even if it fails
"helm uninstall $JOB_NAME -n default --wait || true ",
# Give Helm resources time to fully clean up
"echo 'Waiting 60 seconds for helm uninstall... '",
"sleep 60 ",
"echo 'Attempting regular job and pod deletion... '",
# Track if job exists and attempt standard deletion if it does
"JOB_EXISTS=false",
"if kubectl get job $JOB_NAME &>/dev/null; then JOB_EXISTS=true; kubectl delete job/$JOB_NAME --grace-period=30; else echo 'Job not found, skipping regular deletion'; fi ",
# Track if pods exist and attempt standard deletion if they do
"PODS_EXIST=false",
"if kubectl get pods -l job-name=$JOB_NAME 2>&1 | grep -q 'No resources found'; then echo 'No pods found, skipping deletion'; else PODS_EXIST=true; kubectl delete pods -l job-name=$JOB_NAME --grace-period=30; fi ",
# Only wait if there were resources to delete
"[ \"$JOB_EXISTS\" = true ] || [ \"$PODS_EXIST\" = true ] && { echo 'Waiting 30 seconds for kubectl graceful termination... '; sleep 30; } || echo 'No resources found, skipping wait period' ",
# Attempt force deletion of job if it still exists now
"if kubectl get job $JOB_NAME &>/dev/null; then echo 'Job still exists, using force deletion...'; kubectl delete job $JOB_NAME --force --grace-period=0; else echo 'No job to force delete'; fi ",
# Attempt force deletion of pods if they existed before and still exist now
"if ! kubectl get pods -l job-name=$JOB_NAME 2>&1 | grep -q 'No resources found'; then echo 'Pods still exist, using force deletion...'; kubectl delete pods -l job-name=$JOB_NAME --force --grace-period=0; else echo 'No pods to force delete'; fi ",
"echo 'Cleanup completed'",
)
print("**********cleanup cmd is*********")
print(cleanup)
return cleanup