From 65e2e63170584e3bdb65891fa06c5fd2ccae4505 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Mon, 13 Jun 2016 10:00:39 +0200 Subject: [PATCH] Set AttachOptions.CommandName from kubectl run using corba CommandPath This sets AttachOptions.CommandName dynamically depending on the corba Command hierarchy. If the root command is named e.g. "oc" (for the OpenShift cli) this will result in "oc attach" instead of the static "kubectl attach" before this patch. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1341450 --- pkg/kubectl/cmd/attach.go | 6 ++++-- pkg/kubectl/cmd/run.go | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/kubectl/cmd/attach.go b/pkg/kubectl/cmd/attach.go index 3150bccaee5..d406fa087d9 100644 --- a/pkg/kubectl/cmd/attach.go +++ b/pkg/kubectl/cmd/attach.go @@ -53,8 +53,6 @@ func NewCmdAttach(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) Out: cmdOut, Err: cmdErr, - CommandName: "kubectl attach", - Attach: &DefaultRemoteAttach{}, } cmd := &cobra.Command{ @@ -142,6 +140,10 @@ func (p *AttachOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn } p.Client = client + if p.CommandName == "" { + p.CommandName = cmd.CommandPath() + } + return nil } diff --git a/pkg/kubectl/cmd/run.go b/pkg/kubectl/cmd/run.go index 371dcdf3a3d..915c61d83f6 100644 --- a/pkg/kubectl/cmd/run.go +++ b/pkg/kubectl/cmd/run.go @@ -227,6 +227,8 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob Stdin: interactive, TTY: tty, + CommandName: cmd.Parent().CommandPath() + " attach", + Attach: &DefaultRemoteAttach{}, } config, err := f.ClientConfig() @@ -346,7 +348,6 @@ func handleAttachPod(f *cmdutil.Factory, c *client.Client, pod *api.Pod, opts *A opts.Client = c opts.PodName = pod.Name opts.Namespace = pod.Namespace - opts.CommandName = "kubectl attach" if err := opts.Run(); err != nil { fmt.Fprintf(opts.Out, "Error attaching, falling back to logs: %v\n", err) req, err := f.LogsForObject(pod, &api.PodLogOptions{Container: opts.GetContainerName(pod)})