Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cluster/scripts/node-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ function down() {
done
}

# Adapted from gc-pod-reaper.
# This is necessary because wait_down might block on pods that failed initializing
# e.g., (maybe) because GCP failed to schedule a pod due to Out of Resources
function kill_dead_pods() {
local -r namespace=$1
local -r bad_pods=$(
kubectl get pods -n "$namespace" -o json | \
jq -r '.items[] |
select(
(.status.phase == "Unknown" and .status.reason == "ContainerStatusUnknown") or
(.status.reason == "Evicted") or
(.status.containerStatuses[]?.state.terminated? | .reason == "Error" and .exitCode == 137) or
(.status.initContainerStatuses[]?.state.waiting?.reason == "ContainerStatusUnknown")
) | .metadata.name' | sort -u
);
if [ -z "$bad_pods" ]; then
echo "No bad pods found in $namespace. Skipping.";
return
fi
echo "Found bad pods in $namespace: $bad_pods";
for pod_name in $bad_pods; do
echo "Attempting to delete pod $namespace/$pod_name";
if kubectl delete pod -n "$namespace" "$pod_name"; then
echo "Successfully deleted $namespace/$pod_name";
else
echo "Failed to delete $namespace/$pod_name";
fi
done
Comment on lines +106 to +130

@OriolMunoz-da OriolMunoz-da Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) accepting an optional label selector so callers can scope deletions to the workloads being restored

doesn't seem worth it

--ignore-not-found=true

that sounds reasonable enough

--wait=false

this less so: I do want it to be stuck here because it's much easier to debug than it waiting in wait_down

}

function wait_down() {
local -r namespace=$1
local -r component=$2
Expand Down Expand Up @@ -469,6 +499,8 @@ function main() {
down "$namespace" "$component" "$migration_id"
done

kill_dead_pods "$namespace"

for component in "${components[@]}"; do
wait_down "$namespace" "$component" "$migration_id"
done
Expand Down
Loading