diff --git a/pkg/cmd/exec/exec.go b/pkg/cmd/exec/exec.go index 405807664..4bd0c055e 100644 --- a/pkg/cmd/exec/exec.go +++ b/pkg/cmd/exec/exec.go @@ -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 diff --git a/pkg/cmd/exec/exec_test.go b/pkg/cmd/exec/exec_test.go index af8b9099d..9c041f891 100644 --- a/pkg/cmd/exec/exec_test.go +++ b/pkg/cmd/exec/exec_test.go @@ -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()