mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +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
|
||||
}
|
||||
|
||||
printObj, err := o.ToPrinter("drained")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
drainedNodes := sets.NewString()
|
||||
var fatal error
|
||||
|
||||
for _, info := range o.nodeInfos {
|
||||
if err := o.deleteOrEvictPodsSimple(info); err == nil {
|
||||
drainedNodes.Insert(info.Name)
|
||||
|
||||
printObj, err := o.ToPrinter("drained")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObj(info.Object, o.Out)
|
||||
} else {
|
||||
if o.drainer.IgnoreErrors && len(o.nodeInfos) > 1 {
|
||||
|
@ -546,6 +546,7 @@ func TestDrain(t *testing.T) {
|
||||
expectWarning string
|
||||
expectFatal bool
|
||||
expectDelete bool
|
||||
expectOutputToContain string
|
||||
}{
|
||||
{
|
||||
description: "RC-managed pod",
|
||||
@ -556,6 +557,7 @@ func TestDrain(t *testing.T) {
|
||||
args: []string{"node"},
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
description: "DS-managed pod",
|
||||
@ -576,6 +578,7 @@ func TestDrain(t *testing.T) {
|
||||
args: []string{"node"},
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
description: "orphaned DS-managed pod",
|
||||
@ -597,6 +600,7 @@ func TestDrain(t *testing.T) {
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
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",
|
||||
@ -607,6 +611,7 @@ func TestDrain(t *testing.T) {
|
||||
args: []string{"node", "--ignore-daemonsets"},
|
||||
expectFatal: false,
|
||||
expectDelete: false,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
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",
|
||||
expectFatal: false,
|
||||
expectDelete: false,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
description: "Job-managed pod with local storage",
|
||||
@ -628,6 +634,7 @@ func TestDrain(t *testing.T) {
|
||||
args: []string{"node", "--force", "--delete-emptydir-data=true"},
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
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"},
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
description: "Job-managed terminated pod",
|
||||
@ -648,6 +656,7 @@ func TestDrain(t *testing.T) {
|
||||
args: []string{"node"},
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
description: "RS-managed pod",
|
||||
@ -658,6 +667,7 @@ func TestDrain(t *testing.T) {
|
||||
args: []string{"node"},
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
description: "naked pod",
|
||||
@ -678,6 +688,7 @@ func TestDrain(t *testing.T) {
|
||||
args: []string{"node", "--force"},
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
description: "pod with EmptyDir",
|
||||
@ -697,6 +708,7 @@ func TestDrain(t *testing.T) {
|
||||
args: []string{"node"},
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
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"},
|
||||
expectFatal: false,
|
||||
expectDelete: true,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
description: "empty node",
|
||||
@ -716,6 +729,7 @@ func TestDrain(t *testing.T) {
|
||||
args: []string{"node"},
|
||||
expectFatal: false,
|
||||
expectDelete: false,
|
||||
expectOutputToContain: "node/node drained",
|
||||
},
|
||||
{
|
||||
description: "fail to list pods",
|
||||
@ -859,7 +873,7 @@ func TestDrain(t *testing.T) {
|
||||
}
|
||||
tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
|
||||
|
||||
ioStreams, _, _, errBuf := genericclioptions.NewTestIOStreams()
|
||||
ioStreams, _, outBuf, errBuf := genericclioptions.NewTestIOStreams()
|
||||
cmd := NewCmdDrain(tf, ioStreams)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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