Skip to content

Commit

Permalink
fix: cordon-drain-nodes-older-than-minutes so that it actually waits … (
Browse files Browse the repository at this point in the history
#170)

* fix: cordon-drain-nodes-older-than-minutes so that it actually waits like it did before
  • Loading branch information
venkatamutyala authored Oct 15, 2024
1 parent e1749a8 commit fb442b0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions .devcontainer/tools/cordon-drain-nodes-older-than-minutes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,21 @@ fi
echo -n "Drain the cordoned nodes? (y/N) "
read -r response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "$NODES" | while IFS= read -r node; do
pids=()
while IFS= read -r node; do # Process substitution to avoid subshell
echo "Draining node: $node"
kubectl drain "$node" --ignore-daemonsets --delete-emptydir-data > "drain-${node}.log" 2>&1 &
printf "PID: %s\n" "$!"
pids+=($!)
done < <(echo "$NODES") # Process substitution
# Wait for all PIDs
for pid in "${pids[@]}"; do
printf "Waiting on: %s\n" "$pid" # Debugging output (optional)
wait "$pid"
printf "Finished: %s\n" "$pid" # Debugging output (optional)

done
wait
echo "All nodes drained."
else
echo "Draining skipped."
fi
fi

0 comments on commit fb442b0

Please sign in to comment.