Commit 84c8158b authored by k8s-merge-robot's avatar k8s-merge-robot Committed by GitHub

Merge pull request #27263 from sttts/sttts-kubectl-attach-cmdName

Automatic merge from submit-queue Dynamically derive AttachOptions.CommandName This PR 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
parents cbab337b 65e2e631
...@@ -53,8 +53,6 @@ func NewCmdAttach(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) ...@@ -53,8 +53,6 @@ func NewCmdAttach(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer)
Out: cmdOut, Out: cmdOut,
Err: cmdErr, Err: cmdErr,
CommandName: "kubectl attach",
Attach: &DefaultRemoteAttach{}, Attach: &DefaultRemoteAttach{},
} }
cmd := &cobra.Command{ cmd := &cobra.Command{
...@@ -142,6 +140,10 @@ func (p *AttachOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn ...@@ -142,6 +140,10 @@ func (p *AttachOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn
} }
p.Client = client p.Client = client
if p.CommandName == "" {
p.CommandName = cmd.CommandPath()
}
return nil return nil
} }
......
...@@ -227,6 +227,8 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob ...@@ -227,6 +227,8 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
Stdin: interactive, Stdin: interactive,
TTY: tty, TTY: tty,
CommandName: cmd.Parent().CommandPath() + " attach",
Attach: &DefaultRemoteAttach{}, Attach: &DefaultRemoteAttach{},
} }
config, err := f.ClientConfig() config, err := f.ClientConfig()
...@@ -346,7 +348,6 @@ func handleAttachPod(f *cmdutil.Factory, c *client.Client, pod *api.Pod, opts *A ...@@ -346,7 +348,6 @@ func handleAttachPod(f *cmdutil.Factory, c *client.Client, pod *api.Pod, opts *A
opts.Client = c opts.Client = c
opts.PodName = pod.Name opts.PodName = pod.Name
opts.Namespace = pod.Namespace opts.Namespace = pod.Namespace
opts.CommandName = "kubectl attach"
if err := opts.Run(); err != nil { if err := opts.Run(); err != nil {
fmt.Fprintf(opts.Out, "Error attaching, falling back to logs: %v\n", err) fmt.Fprintf(opts.Out, "Error attaching, falling back to logs: %v\n", err)
req, err := f.LogsForObject(pod, &api.PodLogOptions{Container: opts.GetContainerName(pod)}) req, err := f.LogsForObject(pod, &api.PodLogOptions{Container: opts.GetContainerName(pod)})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment