@@ -99,10 +99,14 @@ usage_percentage=$(df -P "$target_dir" | awk 'NR==2 {print $5}' | sed 's/%%//')
9999echo "[disk usage checker] Volume usage percentage: current = ${usage_percentage} ; allowed = ${usage_percentage_limit}"
100100if [ "$usage_percentage" -gt "$usage_percentage_limit" ]; then
101101 echo "[disk usage checker] Disk usage exceeds the volume percentage of ${usage_percentage_limit} for mounted directory, terminating..."
102- ps -o sess --no-headers | sort -u | while read sid; do
103- [[ "$sid" -eq "${$}" ]] && continue
104- pkill --signal SIGKILL --session "$sid"
105- done
102+ if command -v setsid >/dev/null 2>&1 && command -v ps >/dev/null 2>&1 && command -v pkill >/dev/null 2>&1; then
103+ ps -o sess --no-headers | sort -u | while read sid; do
104+ [[ "$sid" -eq "${$}" ]] && continue
105+ pkill --signal SIGKILL --session "$sid"
106+ done
107+ else
108+ kill 0
109+ fi
106110 exit 1
107111fi
108112sleep 5
@@ -1325,12 +1329,19 @@ func buildPodCommand(
13251329 cmd .WriteString (volumeCheckerScript )
13261330 cmd .WriteString (` & ` )
13271331
1328- // Start the gather command in a separate session.
1329- cmd .WriteString ("setsid -w bash <<-MUSTGATHER_EOF\n " )
1332+ // Start the gather command in a separate session if setsid, ps, and pkill are available.
1333+ // Fall back to simpler approach if any of these tools are not present (minimal images).
1334+ cmd .WriteString ("if command -v setsid >/dev/null 2>&1 && command -v ps >/dev/null 2>&1 && command -v pkill >/dev/null 2>&1; then\n " )
1335+ cmd .WriteString (" setsid -w bash <<-MUSTGATHER_EOF\n " )
13301336 cmd .WriteString (gatherCommand )
13311337 cmd .WriteString ("\n MUSTGATHER_EOF\n " )
1338+ cmd .WriteString ("else\n " )
1339+ cmd .WriteString (" " )
1340+ cmd .WriteString (gatherCommand )
1341+ cmd .WriteString ("\n fi; " )
13321342
13331343 // Make sure all changes are written to disk.
13341344 cmd .WriteString (`sync && echo 'Caches written to disk'` )
1345+
13351346 return cmd .String ()
13361347}
0 commit comments