Skip to content

Commit 23bf338

Browse files
authored
Ensure that the cordon command doesn't stop when a node doesn't host any pods (#2260)
1 parent e1d479f commit 23bf338

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

Diff for: kubectl-fdb/cmd/cordon.go

+23-9
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,26 @@ func cordonNode(cmd *cobra.Command, kubeClient client.Client, inputClusterName s
129129
return errors.New("no nodes were provided for cordoning")
130130
}
131131

132-
var totalRemoved int
133-
132+
statistics := map[string]int{}
133+
var observedErrors []error
134134
for _, node := range nodes {
135135
pods, err := fetchPodsOnNode(kubeClient, inputClusterName, namespace, node, clusterLabel)
136136
if err != nil {
137-
return fmt.Errorf("issue fetching Pods running on node %s. Error: %w", node, err)
137+
observedErrors = append(observedErrors, fmt.Errorf("error fetching Pods from node: %s", node))
138+
continue
138139
}
140+
139141
if len(pods.Items) == 0 {
140-
return fmt.Errorf("no pods were found that were running on node %s", node)
142+
cmd.PrintErrln("Cordoning node:", node, "has no running pods")
143+
continue
141144
}
145+
142146
var podNames []string
143147
for _, pod := range pods.Items {
144148
podNames = append(podNames, pod.Name)
145149
}
146150

147-
cmd.Printf("\nCordoning node: %s\n", node)
151+
cmd.Println("Cordoning node:", node)
148152
removedFromNode, err := replaceProcessGroups(cmd, kubeClient,
149153
processGroupSelectionOptions{
150154
ids: podNames,
@@ -160,10 +164,20 @@ func cordonNode(cmd *cobra.Command, kubeClient client.Client, inputClusterName s
160164
removeAllFailed: false,
161165
})
162166
if err != nil {
163-
return fmt.Errorf("unable to cordon all Pods running on node %s. Error: %s", node, err.Error())
167+
observedErrors = append(observedErrors, fmt.Errorf("unable to cordon all Pods on node %s", node))
168+
continue
164169
}
165-
totalRemoved += removedFromNode
170+
171+
statistics[node] = removedFromNode
166172
}
167-
cmd.Printf("\nCompleted removal of %d Pods\n", totalRemoved)
168-
return nil
173+
174+
cmd.Println("Completed removal cordoning, printing summary:")
175+
var total int
176+
for _, node := range nodes {
177+
cmd.Println("Removed:", statistics[node], "pods from node:", node)
178+
total += statistics[node]
179+
}
180+
cmd.Println("Removed:", total, "pods from", len(nodes), "nodes")
181+
182+
return errors.Join(observedErrors...)
169183
}

Diff for: kubectl-fdb/cmd/cordon_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var _ = Describe("[plugin] cordon command", func() {
109109
ExpectedInstancesToRemoveWithoutExclusion: []fdbv1beta2.ProcessGroupID{},
110110
clusterName: clusterName,
111111
clusterLabel: "",
112-
wantErrorContains: "no pods were found that were running on node",
112+
wantErrorContains: "",
113113
}),
114114
Entry("Cordon no node nodes without exclusion",
115115
testCase{
@@ -119,7 +119,7 @@ var _ = Describe("[plugin] cordon command", func() {
119119
ExpectedInstancesToRemoveWithoutExclusion: []fdbv1beta2.ProcessGroupID{},
120120
clusterName: clusterName,
121121
clusterLabel: "",
122-
wantErrorContains: "no pods were found that were running on node",
122+
wantErrorContains: "",
123123
}),
124124
Entry("Cordon all nodes with exclusion",
125125
testCase{
@@ -197,7 +197,7 @@ var _ = Describe("[plugin] cordon command", func() {
197197
ExpectedInstancesToRemoveWithoutExclusion: []fdbv1beta2.ProcessGroupID{},
198198
clusterName: "",
199199
clusterLabel: fdbv1beta2.FDBClusterLabel,
200-
wantErrorContains: "no pods were found that were running on node",
200+
wantErrorContains: "",
201201
}),
202202
)
203203
})

0 commit comments

Comments
 (0)