From f8cc2ab3b86cfed56c8447ea67d6d5c36b54b35c Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Wed, 7 Sep 2016 11:23:21 -0400 Subject: [PATCH] add suggestion to use `describe` to obtain container names --- pkg/kubectl/cmd/cmd.go | 2 +- pkg/kubectl/cmd/exec.go | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 9d9caaab66d..33023f52410 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -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), }, diff --git a/pkg/kubectl/cmd/exec.go b/pkg/kubectl/cmd/exec.go index 4c9afcb4eb5..baf8377e286 100644 --- a/pkg/kubectl/cmd/exec.go +++ b/pkg/kubectl/cmd/exec.go @@ -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 }