mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #30717 from juanvallejo/jvallejo_add-oc-describe-help-suggestion
Automatic merge from submit-queue add suggestion to use `describe` to obtain container names **Release note**: ```release-note release-note-none ``` Commands with the `--container=` option provide no suggestions to a user on how to obtain a container's name from a pod. This patch adds a suggestion on the usage output to use the `describe` command on a pod to obtain the container value that is passed to the `--container=` flag. `$ kubectl exec -h` ``` Execute a command in a container. Examples: kubectl exec 123456-7890 date kubectl exec 123456-7890 -c ruby-container date kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il Flags: -c, --container string Container name. If omitted, the first container in the pod will be chosen. Use the 'describe' command to find the list of containers on a pod. -p, --pod string Pod name -i, --stdin Pass stdin to the container -t, --tty Stdin is a TTY
This commit is contained in:
commit
f9e1ef97db
@ -287,7 +287,7 @@ Find more information at https://github.com/kubernetes/kubernetes.`,
|
||||
NewCmdDescribe(f, out, err),
|
||||
NewCmdLogs(f, out),
|
||||
NewCmdAttach(f, in, out, err),
|
||||
NewCmdExec(f, in, out, err),
|
||||
NewCmdExec("kubectl", f, in, out, err),
|
||||
NewCmdPortForward(f, out, err),
|
||||
NewCmdProxy(f, out),
|
||||
},
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"net/url"
|
||||
|
||||
dockerterm "github.com/docker/docker/pkg/term"
|
||||
"github.com/golang/glog"
|
||||
"github.com/renstrom/dedent"
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@ -52,7 +51,7 @@ const (
|
||||
execUsageStr = "expected 'exec POD_NAME COMMAND [ARG1] [ARG2] ... [ARGN]'.\nPOD_NAME and COMMAND are required arguments for the exec command"
|
||||
)
|
||||
|
||||
func NewCmdExec(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {
|
||||
func NewCmdExec(cmdFullName string, f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {
|
||||
options := &ExecOptions{
|
||||
StreamOptions: StreamOptions{
|
||||
In: cmdIn,
|
||||
@ -60,7 +59,8 @@ func NewCmdExec(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *
|
||||
Err: cmdErr,
|
||||
},
|
||||
|
||||
Executor: &DefaultRemoteExecutor{},
|
||||
FullCmdName: cmdFullName,
|
||||
Executor: &DefaultRemoteExecutor{},
|
||||
}
|
||||
cmd := &cobra.Command{
|
||||
Use: "exec POD [-c CONTAINER] -- COMMAND [args...]",
|
||||
@ -130,13 +130,18 @@ type ExecOptions struct {
|
||||
|
||||
Command []string
|
||||
|
||||
Executor RemoteExecutor
|
||||
Client *client.Client
|
||||
Config *restclient.Config
|
||||
FullCmdName string
|
||||
Executor RemoteExecutor
|
||||
Client *client.Client
|
||||
Config *restclient.Config
|
||||
}
|
||||
|
||||
// Complete verifies command line arguments and loads data from the command environment
|
||||
func (p *ExecOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn []string, argsLenAtDash int) error {
|
||||
if len(p.FullCmdName) == 0 {
|
||||
p.FullCmdName = "kubectl"
|
||||
}
|
||||
|
||||
// Let kubectl exec follow rules for `--`, see #13004 issue
|
||||
if len(p.PodName) == 0 && (len(argsIn) == 0 || argsLenAtDash == 0) {
|
||||
return cmdutil.UsageError(cmd, execUsageStr)
|
||||
@ -258,7 +263,9 @@ func (p *ExecOptions) Run() error {
|
||||
|
||||
containerName := p.ContainerName
|
||||
if len(containerName) == 0 {
|
||||
glog.V(4).Infof("defaulting container name to %s", pod.Spec.Containers[0].Name)
|
||||
if len(pod.Spec.Containers) > 1 {
|
||||
fmt.Fprintf(p.Err, "defaulting container name to %s, use '%s describe pod/%s' to see all container names\n", pod.Spec.Containers[0].Name, p.FullCmdName, p.PodName)
|
||||
}
|
||||
containerName = pod.Spec.Containers[0].Name
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user