Skip to content

Commit e3c8add

Browse files
committed
fix kubectl drain ignore daemonsets and others
1 parent 2b6d875 commit e3c8add

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/drain/drain_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ func TestDrain(t *testing.T) {
867867
switch {
868868
case recovered != nil && !sawFatal:
869869
t.Fatalf("got panic: %v", recovered)
870-
case test.expectDelete && test.expectFatal && !sawFatal:
870+
case test.expectFatal && !sawFatal:
871871
t.Fatalf("%s: unexpected non-error when using %s", test.description, currMethod)
872872
case !test.expectFatal && sawFatal:
873873
t.Fatalf("%s: unexpected error when using %s: %s", test.description, currMethod, fatalMsg)
@@ -903,7 +903,7 @@ func TestDrain(t *testing.T) {
903903
t.Fatalf("%s: same pod deleted %d times and evicted %d times", test.description, deletions, evictions)
904904
}
905905

906-
if test.expectDelete && len(test.expectWarning) > 0 {
906+
if len(test.expectWarning) > 0 {
907907
if len(errBuf.String()) == 0 {
908908
t.Fatalf("%s: expected warning, but found no stderr output", test.description)
909909
}

staging/src/k8s.io/kubectl/pkg/drain/drain.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,13 @@ func (d *Helper) GetPodsForDeletion(nodeName string) (*podDeleteList, []error) {
180180
break
181181
}
182182
}
183-
if status.delete {
184-
pods = append(pods, podDelete{
185-
pod: pod,
186-
status: status,
187-
})
188-
}
183+
// Add the pod to podDeleteList no matter what podDeleteStatus is,
184+
// those pods whose podDeleteStatus is false like DaemonSet will
185+
// be catched by list.errors()
186+
pods = append(pods, podDelete{
187+
pod: pod,
188+
status: status,
189+
})
189190
}
190191

191192
list := &podDeleteList{items: pods}

0 commit comments

Comments
 (0)