Skip to content

Commit 5cd5388

Browse files
author
michael stack
committed
* k8s/agent-scaler/agent-scaler.sh
Add --ignore-not-found=true to delete. Cleans up some complaint when two scripts running beside each other and one deletes first (happens when testing changes to this script). Minor item. Also, clean up 'Failed' jobs else they just hang out.
1 parent fe73372 commit 5cd5388

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

k8s/agent-scaler/agent-scaler.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ while true; do
4848
# Filter by AGENT_NAME and check 3rd column for "1/1" (completions)
4949
for job in $(kubectl get jobs -n "${namespace}" --no-headers | { grep -E -e "^${AGENT_NAME}-[0-9]+(-[0-9]+)?\\s" || true; } | awk '$3 == "1/1" {print $1}'); do
5050
echo "=== Job $job Completed (1/1) - deleting from get jobs === (AGENT_NAME: ${AGENT_NAME})"
51-
kubectl delete job "$job" -n "${namespace}"
51+
kubectl delete job "$job" -n "${namespace}" --ignore-not-found=true
52+
done
53+
54+
# cleanup explicitly Failed jobs
55+
# Filter by AGENT_NAME and job status condition "Failed"="True"
56+
for job in $(kubectl get jobs -n "${namespace}" -o jsonpath='{range .items[?(@.status.conditions[*].type=="Failed" && @.status.conditions[*].status=="True")]}{.metadata.name}{"\\n"}{end}' 2>/dev/null | { grep -E "^${AGENT_NAME}-[0-9]+(-[0-9]+)?$" || true; }); do
57+
if [ -n "$job" ]; then # Ensure job name is not empty
58+
echo "=== Job $job is Failed - deleting === (AGENT_NAME: ${AGENT_NAME})"
59+
kubectl delete job "$job" -n "${namespace}" --ignore-not-found=true
60+
fi
5261
done
5362

5463
# cleanup failed/completed jobs by looking at pods for the current AGENT_NAME

0 commit comments

Comments
 (0)