Remove deprecated kubectl exec command execution without dash (#125437)
* Remove deprecated kubectl exec command execution without dash * Use command execution with dash in kubectl exec * Modify unit tests to only use command after dash Kubernetes-commit: 6f4e97e905e5553e75a5a8c042c9f5a29bd1b78d
This commit is contained in:
parent
f508e12184
commit
d5a8f05803
|
@ -200,17 +200,8 @@ func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []s
|
|||
}
|
||||
if argsLenAtDash > -1 {
|
||||
p.Command = argsIn[argsLenAtDash:]
|
||||
} else if len(argsIn) > 1 {
|
||||
if !p.Quiet {
|
||||
fmt.Fprint(p.ErrOut, "kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.\n")
|
||||
}
|
||||
p.Command = argsIn[1:]
|
||||
} else if len(argsIn) > 0 && len(p.FilenameOptions.Filenames) != 0 {
|
||||
if !p.Quiet {
|
||||
fmt.Fprint(p.ErrOut, "kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.\n")
|
||||
}
|
||||
p.Command = argsIn[0:]
|
||||
p.ResourceName = ""
|
||||
} else if len(argsIn) > 1 || (len(argsIn) > 0 && len(p.FilenameOptions.Filenames) != 0) {
|
||||
return cmdutil.UsageErrorf(cmd, "exec [POD] [COMMAND] is not supported anymore. Use exec [POD] -- [COMMAND] instead")
|
||||
}
|
||||
|
||||
var err error
|
||||
|
|
|
@ -110,20 +110,17 @@ func TestPodAndContainer(t *testing.T) {
|
|||
p: &ExecOptions{},
|
||||
args: []string{"foo", "cmd"},
|
||||
argsLenAtDash: -1,
|
||||
expectedPod: "foo",
|
||||
expectedArgs: []string{"cmd"},
|
||||
expectError: true,
|
||||
name: "cmd, cmd is behind dash",
|
||||
obj: execPod(),
|
||||
},
|
||||
{
|
||||
p: &ExecOptions{StreamOptions: StreamOptions{ContainerName: "bar"}},
|
||||
args: []string{"foo", "cmd"},
|
||||
argsLenAtDash: -1,
|
||||
expectedPod: "foo",
|
||||
expectedContainer: "bar",
|
||||
expectedArgs: []string{"cmd"},
|
||||
name: "cmd, container in flag",
|
||||
obj: execPod(),
|
||||
p: &ExecOptions{StreamOptions: StreamOptions{ContainerName: "bar"}},
|
||||
args: []string{"foo", "cmd"},
|
||||
argsLenAtDash: -1,
|
||||
expectError: true,
|
||||
name: "cmd, container in flag",
|
||||
obj: execPod(),
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
|
@ -238,8 +235,8 @@ func TestExec(t *testing.T) {
|
|||
Executor: ex,
|
||||
}
|
||||
cmd := NewCmdExec(tf, genericiooptions.NewTestIOStreamsDiscard())
|
||||
args := []string{"pod/foo", "command"}
|
||||
if err := params.Complete(tf, cmd, args, -1); err != nil {
|
||||
args := []string{"pod/foo", "--", "command"}
|
||||
if err := params.Complete(tf, cmd, args, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := params.Run()
|
||||
|
|
Loading…
Reference in New Issue