From 94b91c1d5184a2f6da7681a425f15ca0ae5ebdec Mon Sep 17 00:00:00 2001 From: zhouya0 Date: Sun, 19 Jan 2020 14:28:53 +0800 Subject: [PATCH] fix kubectl drain ignore daemonsets and others Kubernetes-commit: e3c8add683a095f1bffef1b0ca413f1e42be7fe0 --- pkg/cmd/drain/drain_test.go | 4 ++-- pkg/drain/drain.go | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/drain/drain_test.go b/pkg/cmd/drain/drain_test.go index e3b449ce..83e88dc0 100644 --- a/pkg/cmd/drain/drain_test.go +++ b/pkg/cmd/drain/drain_test.go @@ -867,7 +867,7 @@ func TestDrain(t *testing.T) { switch { case recovered != nil && !sawFatal: t.Fatalf("got panic: %v", recovered) - case test.expectDelete && test.expectFatal && !sawFatal: + case test.expectFatal && !sawFatal: t.Fatalf("%s: unexpected non-error when using %s", test.description, currMethod) case !test.expectFatal && sawFatal: t.Fatalf("%s: unexpected error when using %s: %s", test.description, currMethod, fatalMsg) @@ -903,7 +903,7 @@ func TestDrain(t *testing.T) { t.Fatalf("%s: same pod deleted %d times and evicted %d times", test.description, deletions, evictions) } - if test.expectDelete && len(test.expectWarning) > 0 { + if len(test.expectWarning) > 0 { if len(errBuf.String()) == 0 { t.Fatalf("%s: expected warning, but found no stderr output", test.description) } diff --git a/pkg/drain/drain.go b/pkg/drain/drain.go index ae6f166a..fefe0b5a 100644 --- a/pkg/drain/drain.go +++ b/pkg/drain/drain.go @@ -180,12 +180,13 @@ func (d *Helper) GetPodsForDeletion(nodeName string) (*podDeleteList, []error) { break } } - if status.delete { - pods = append(pods, podDelete{ - pod: pod, - status: status, - }) - } + // Add the pod to podDeleteList no matter what podDeleteStatus is, + // those pods whose podDeleteStatus is false like DaemonSet will + // be catched by list.errors() + pods = append(pods, podDelete{ + pod: pod, + status: status, + }) } list := &podDeleteList{items: pods}