Support multiple arguments for cordon and drain

pull/58/head
goodluckbot 2018-11-12 00:28:36 +08:00
parent a3ccea9d87
commit df31468ce7
2 changed files with 25 additions and 4 deletions

View File

@ -235,9 +235,6 @@ func (o *DrainOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
if len(args) > 0 && len(o.Selector) > 0 {
return cmdutil.UsageErrorf(cmd, "error: cannot specify both a node name and a --selector option")
}
if len(args) > 0 && len(args) != 1 {
return cmdutil.UsageErrorf(cmd, fmt.Sprintf("USAGE: %s [flags]", cmd.Use))
}
o.DryRun = cmdutil.GetDryRunFlag(cmd)

View File

@ -142,6 +142,22 @@ func TestCordon(t *testing.T) {
arg: "bar",
expectFatal: true,
},
{
description: "cordon for multiple nodes",
node: node,
expected: cordoned_node,
cmd: NewCmdCordon,
arg: "node node1 node2",
expectFatal: false,
},
{
description: "uncordon for multiple nodes",
node: cordoned_node,
expected: node,
cmd: NewCmdUncordon,
arg: "node node1 node2",
expectFatal: false,
},
}
for _, test := range tests {
@ -160,10 +176,18 @@ func TestCordon(t *testing.T) {
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
m := &MyReq{req}
switch {
case m.isFor("GET", "/nodes/node1"):
fallthrough
case m.isFor("GET", "/nodes/node2"):
fallthrough
case m.isFor("GET", "/nodes/node"):
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, test.node)}, nil
case m.isFor("GET", "/nodes/bar"):
return &http.Response{StatusCode: 404, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.StringBody("nope")}, nil
case m.isFor("PATCH", "/nodes/node1"):
fallthrough
case m.isFor("PATCH", "/nodes/node2"):
fallthrough
case m.isFor("PATCH", "/nodes/node"):
data, err := ioutil.ReadAll(req.Body)
if err != nil {
@ -209,7 +233,7 @@ func TestCordon(t *testing.T) {
saw_fatal = true
panic(e)
})
cmd.SetArgs([]string{test.arg})
cmd.SetArgs(strings.Split(test.arg, " "))
cmd.Execute()
}()