mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
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
This commit is contained in:
parent
7060e48569
commit
6f4e97e905
@ -200,17 +200,8 @@ func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []s
|
|||||||
}
|
}
|
||||||
if argsLenAtDash > -1 {
|
if argsLenAtDash > -1 {
|
||||||
p.Command = argsIn[argsLenAtDash:]
|
p.Command = argsIn[argsLenAtDash:]
|
||||||
} else if len(argsIn) > 1 {
|
} else if len(argsIn) > 1 || (len(argsIn) > 0 && len(p.FilenameOptions.Filenames) != 0) {
|
||||||
if !p.Quiet {
|
return cmdutil.UsageErrorf(cmd, "exec [POD] [COMMAND] is not supported anymore. Use exec [POD] -- [COMMAND] instead")
|
||||||
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 = ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -110,8 +110,7 @@ func TestPodAndContainer(t *testing.T) {
|
|||||||
p: &ExecOptions{},
|
p: &ExecOptions{},
|
||||||
args: []string{"foo", "cmd"},
|
args: []string{"foo", "cmd"},
|
||||||
argsLenAtDash: -1,
|
argsLenAtDash: -1,
|
||||||
expectedPod: "foo",
|
expectError: true,
|
||||||
expectedArgs: []string{"cmd"},
|
|
||||||
name: "cmd, cmd is behind dash",
|
name: "cmd, cmd is behind dash",
|
||||||
obj: execPod(),
|
obj: execPod(),
|
||||||
},
|
},
|
||||||
@ -119,9 +118,7 @@ func TestPodAndContainer(t *testing.T) {
|
|||||||
p: &ExecOptions{StreamOptions: StreamOptions{ContainerName: "bar"}},
|
p: &ExecOptions{StreamOptions: StreamOptions{ContainerName: "bar"}},
|
||||||
args: []string{"foo", "cmd"},
|
args: []string{"foo", "cmd"},
|
||||||
argsLenAtDash: -1,
|
argsLenAtDash: -1,
|
||||||
expectedPod: "foo",
|
expectError: true,
|
||||||
expectedContainer: "bar",
|
|
||||||
expectedArgs: []string{"cmd"},
|
|
||||||
name: "cmd, container in flag",
|
name: "cmd, container in flag",
|
||||||
obj: execPod(),
|
obj: execPod(),
|
||||||
},
|
},
|
||||||
@ -238,8 +235,8 @@ func TestExec(t *testing.T) {
|
|||||||
Executor: ex,
|
Executor: ex,
|
||||||
}
|
}
|
||||||
cmd := NewCmdExec(tf, genericiooptions.NewTestIOStreamsDiscard())
|
cmd := NewCmdExec(tf, genericiooptions.NewTestIOStreamsDiscard())
|
||||||
args := []string{"pod/foo", "command"}
|
args := []string{"pod/foo", "--", "command"}
|
||||||
if err := params.Complete(tf, cmd, args, -1); err != nil {
|
if err := params.Complete(tf, cmd, args, 1); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
err := params.Run()
|
err := params.Run()
|
||||||
|
@ -26,7 +26,7 @@ run_kubectl_exec_pod_tests() {
|
|||||||
kube::log::status "Testing kubectl exec POD COMMAND"
|
kube::log::status "Testing kubectl exec POD COMMAND"
|
||||||
|
|
||||||
### Test execute non-existing POD
|
### Test execute non-existing POD
|
||||||
output_message=$(! kubectl exec abc date 2>&1)
|
output_message=$(! kubectl exec abc 2>&1 -- date)
|
||||||
# POD abc should error since it doesn't exist
|
# POD abc should error since it doesn't exist
|
||||||
kube::test::if_has_string "${output_message}" 'pods "abc" not found'
|
kube::test::if_has_string "${output_message}" 'pods "abc" not found'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user