From 8a2610c6fb2e7633a896f5ef6aecb19cdcaf91ef Mon Sep 17 00:00:00 2001 From: ymqytw Date: Mon, 24 Oct 2016 09:32:49 -0700 Subject: [PATCH] fix drain test flake --- pkg/kubectl/cmd/drain.go | 7 +------ pkg/kubectl/cmd/drain_test.go | 6 ++++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/kubectl/cmd/drain.go b/pkg/kubectl/cmd/drain.go index 7257f0c00d..e29521b2ff 100644 --- a/pkg/kubectl/cmd/drain.go +++ b/pkg/kubectl/cmd/drain.go @@ -54,7 +54,6 @@ type DrainOptions struct { nodeInfo *resource.Info out io.Writer typer runtime.ObjectTyper - ifPrint bool } // Takes a pod and returns a bool indicating whether or not to operate on the @@ -198,8 +197,6 @@ func (o *DrainOptions) SetupDrain(cmd *cobra.Command, args []string) error { return err } - o.ifPrint = true - r := o.factory.NewBuilder(). NamespaceParam(cmdNamespace).DefaultNamespace(). ResourceNames("node", args[0]). @@ -422,9 +419,7 @@ func (o *DrainOptions) waitForDelete(pods []api.Pod, interval, timeout time.Dura for i, pod := range pods { p, err := getPodFn(pod.Namespace, pod.Name) if apierrors.IsNotFound(err) || (p != nil && p.ObjectMeta.UID != pod.ObjectMeta.UID) { - if o.ifPrint { - cmdutil.PrintSuccess(o.mapper, false, o.out, "pod", pod.Name, false, "deleted") - } + cmdutil.PrintSuccess(o.mapper, false, o.out, "pod", pod.Name, false, "deleted") continue } else if err != nil { return false, err diff --git a/pkg/kubectl/cmd/drain_test.go b/pkg/kubectl/cmd/drain_test.go index d690da79a4..66d44ace53 100644 --- a/pkg/kubectl/cmd/drain_test.go +++ b/pkg/kubectl/cmd/drain_test.go @@ -621,9 +621,11 @@ func TestDeletePods(t *testing.T) { }, } - o := DrainOptions{} - o.ifPrint = false for _, test := range tests { + f, _, _, _ := cmdtesting.NewAPIFactory() + o := DrainOptions{} + o.mapper, _ = f.Object() + o.out = os.Stdout _, pods := createPods(false) pendingPods, err := o.waitForDelete(pods, test.interval, test.timeout, test.getPodFn)