Skip to content

Kill dead pods in node restore - #6985

Open
OriolMunoz-da wants to merge 3 commits into
mainfrom
oriol/node-restore-dead-pods
Open

Kill dead pods in node restore#6985
OriolMunoz-da wants to merge 3 commits into
mainfrom
oriol/node-restore-dead-pods

Conversation

@OriolMunoz-da

Copy link
Copy Markdown
Contributor

[static]

Signed-off-by: Oriol Muñoz <oriol.munoz@digitalasset.com>
Signed-off-by: Oriol Muñoz <oriol.munoz@digitalasset.com>
@OriolMunoz-da
OriolMunoz-da requested a lite review from Copilot August 26, 2026 16:50
@OriolMunoz-da OriolMunoz-da changed the title Kill dead pods before node restore Kill dead pods in node restore Aug 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the node restore workflow to proactively remove “dead” Kubernetes pods after scaling down components, preventing wait_down from blocking indefinitely on pods stuck in bad states (e.g., evicted/unknown).

Changes:

  • Add a kill_dead_pods helper to identify and delete pods in problematic states before waiting for scale-down completion.
  • Invoke the new cleanup step in main() after scaling down components and before wait_down.
Suppressed comments (1)

cluster/scripts/node-restore.sh:506

  • kill_dead_pods is called without any scoping, so it may delete unrelated “bad” pods in the namespace (e.g., from components not being restored). Since wait_down waits on app=$deployment_name, it’s safer to scope pod cleanup to the same set of app labels derived from the components being restored.
  kill_dead_pods "$namespace"

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

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +106 to +130
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

@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

Signed-off-by: Oriol Muñoz <oriol.munoz@digitalasset.com>
@OriolMunoz-da

Copy link
Copy Markdown
Contributor Author

/cluster_test

@github-actions

Copy link
Copy Markdown

Deploy cluster test triggered for Commit 357aefceeea706078cabba0d41f3d490ef7bed93 in , please contact a Contributor to approve it in CircleCI: https://app.circleci.com/pipelines/github/DACH-NY/canton-network-internal/80000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants