From 65c2f61806468d25795516d6077ce0c31c83adcd Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Wed, 30 Oct 2019 09:55:34 -0700 Subject: [PATCH] Only put un-filtered pod in podDeleteList --- staging/src/k8s.io/kubectl/pkg/cmd/drain/drain_test.go | 4 ++-- staging/src/k8s.io/kubectl/pkg/drain/drain.go | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/drain/drain_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/drain/drain_test.go index cf0e8e61a2a..81cad757c83 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/drain/drain_test.go +++ b/staging/src/k8s.io/kubectl/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.expectFatal && !sawFatal: + case test.expectDelete && 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 len(test.expectWarning) > 0 { + if test.expectDelete && len(test.expectWarning) > 0 { if len(errBuf.String()) == 0 { t.Fatalf("%s: expected warning, but found no stderr output", test.description) } diff --git a/staging/src/k8s.io/kubectl/pkg/drain/drain.go b/staging/src/k8s.io/kubectl/pkg/drain/drain.go index a941b74935a..d123dd33554 100644 --- a/staging/src/k8s.io/kubectl/pkg/drain/drain.go +++ b/staging/src/k8s.io/kubectl/pkg/drain/drain.go @@ -155,10 +155,12 @@ func (d *Helper) GetPodsForDeletion(nodeName string) (*podDeleteList, []error) { break } } - pods = append(pods, podDelete{ - pod: pod, - status: status, - }) + if status.delete { + pods = append(pods, podDelete{ + pod: pod, + status: status, + }) + } } list := &podDeleteList{items: pods}