mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #105736 from deejross/drain-output-ffix
kubectl drain node output should say node was drained not evicted
This commit is contained in:
commit
3fb98823c4
@ -297,17 +297,18 @@ func (o *DrainCmdOptions) RunDrain() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
printObj, err := o.ToPrinter("drained")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
drainedNodes := sets.NewString()
|
drainedNodes := sets.NewString()
|
||||||
var fatal error
|
var fatal error
|
||||||
|
|
||||||
for _, info := range o.nodeInfos {
|
for _, info := range o.nodeInfos {
|
||||||
if err := o.deleteOrEvictPodsSimple(info); err == nil {
|
if err := o.deleteOrEvictPodsSimple(info); err == nil {
|
||||||
drainedNodes.Insert(info.Name)
|
drainedNodes.Insert(info.Name)
|
||||||
|
|
||||||
|
printObj, err := o.ToPrinter("drained")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
printObj(info.Object, o.Out)
|
printObj(info.Object, o.Out)
|
||||||
} else {
|
} else {
|
||||||
if o.drainer.IgnoreErrors && len(o.nodeInfos) > 1 {
|
if o.drainer.IgnoreErrors && len(o.nodeInfos) > 1 {
|
||||||
|
@ -546,6 +546,7 @@ func TestDrain(t *testing.T) {
|
|||||||
expectWarning string
|
expectWarning string
|
||||||
expectFatal bool
|
expectFatal bool
|
||||||
expectDelete bool
|
expectDelete bool
|
||||||
|
expectOutputToContain string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
description: "RC-managed pod",
|
description: "RC-managed pod",
|
||||||
@ -556,6 +557,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node"},
|
args: []string{"node"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "DS-managed pod",
|
description: "DS-managed pod",
|
||||||
@ -576,6 +578,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node"},
|
args: []string{"node"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "orphaned DS-managed pod",
|
description: "orphaned DS-managed pod",
|
||||||
@ -597,6 +600,7 @@ func TestDrain(t *testing.T) {
|
|||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
expectWarning: "WARNING: deleting Pods not managed by ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet: default/bar",
|
expectWarning: "WARNING: deleting Pods not managed by ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet: default/bar",
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "DS-managed pod with --ignore-daemonsets",
|
description: "DS-managed pod with --ignore-daemonsets",
|
||||||
@ -607,6 +611,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node", "--ignore-daemonsets"},
|
args: []string{"node", "--ignore-daemonsets"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: false,
|
expectDelete: false,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "DS-managed pod with emptyDir with --ignore-daemonsets",
|
description: "DS-managed pod with emptyDir with --ignore-daemonsets",
|
||||||
@ -618,6 +623,7 @@ func TestDrain(t *testing.T) {
|
|||||||
expectWarning: "WARNING: ignoring DaemonSet-managed Pods: default/bar",
|
expectWarning: "WARNING: ignoring DaemonSet-managed Pods: default/bar",
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: false,
|
expectDelete: false,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Job-managed pod with local storage",
|
description: "Job-managed pod with local storage",
|
||||||
@ -628,6 +634,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node", "--force", "--delete-emptydir-data=true"},
|
args: []string{"node", "--force", "--delete-emptydir-data=true"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Ensure compatibility for --delete-local-data until fully deprecated",
|
description: "Ensure compatibility for --delete-local-data until fully deprecated",
|
||||||
@ -638,6 +645,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node", "--force", "--delete-local-data=true"},
|
args: []string{"node", "--force", "--delete-local-data=true"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Job-managed terminated pod",
|
description: "Job-managed terminated pod",
|
||||||
@ -648,6 +656,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node"},
|
args: []string{"node"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "RS-managed pod",
|
description: "RS-managed pod",
|
||||||
@ -658,6 +667,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node"},
|
args: []string{"node"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "naked pod",
|
description: "naked pod",
|
||||||
@ -678,6 +688,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node", "--force"},
|
args: []string{"node", "--force"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "pod with EmptyDir",
|
description: "pod with EmptyDir",
|
||||||
@ -697,6 +708,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node"},
|
args: []string{"node"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "pod with EmptyDir and --delete-emptydir-data",
|
description: "pod with EmptyDir and --delete-emptydir-data",
|
||||||
@ -706,6 +718,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node", "--force", "--delete-emptydir-data=true"},
|
args: []string{"node", "--force", "--delete-emptydir-data=true"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: true,
|
expectDelete: true,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "empty node",
|
description: "empty node",
|
||||||
@ -716,6 +729,7 @@ func TestDrain(t *testing.T) {
|
|||||||
args: []string{"node"},
|
args: []string{"node"},
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: false,
|
expectDelete: false,
|
||||||
|
expectOutputToContain: "node/node drained",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "fail to list pods",
|
description: "fail to list pods",
|
||||||
@ -859,7 +873,7 @@ func TestDrain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
|
tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
|
||||||
|
|
||||||
ioStreams, _, _, errBuf := genericclioptions.NewTestIOStreams()
|
ioStreams, _, outBuf, errBuf := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdDrain(tf, ioStreams)
|
cmd := NewCmdDrain(tf, ioStreams)
|
||||||
|
|
||||||
var recovered interface{}
|
var recovered interface{}
|
||||||
@ -925,6 +939,13 @@ func TestDrain(t *testing.T) {
|
|||||||
t.Fatalf("%s: actual warning message did not match expected warning message.\n Expecting:\n%v\n Got:\n%v", test.description, e, a)
|
t.Fatalf("%s: actual warning message did not match expected warning message.\n Expecting:\n%v\n Got:\n%v", test.description, e, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(test.expectOutputToContain) > 0 {
|
||||||
|
out := outBuf.String()
|
||||||
|
if !strings.Contains(out, test.expectOutputToContain) {
|
||||||
|
t.Fatalf("%s: expected output to contain: %s\nGot:\n%s", test.description, test.expectOutputToContain, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user