Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: The pod name is missing in suggested cmd usage when executing : What you expected to happen: The suggested cmd usage should be a complete cmd like the one got from How to reproduce it (as minimally and precisely as possible): Use to attach any pod/deployment/service, the PodName will be missing in the suggested cmd usage like above. Anything else we need to know?: It works fine for kubectl < v1.12 Environment: Kubernetes version (use ): v1.13.1 Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others:
/sig cli /assign

Discussion:
// whether to disable use of standard error when streaming output from tty DisableStderr bool <del> CommandName       string SuggestedCmdUsage string </del> <ins> CommandName             string ParentCommandName       string EnableSuggestedCmdUsage bool </ins> Pod *corev1.Pod

o.Resources = args o.restClientGetter = f <del> fullCmdName := "" </del> cmdParent := cmd.Parent() if cmdParent != nil { <del> fullCmdName = cmdParent.CommandPath() </del> <ins> o.ParentCommandName = cmdParent.CommandPath() </ins> } <del> if len(fullCmdName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "describe") { o.SuggestedCmdUsage = fmt.Sprintf("Use '%s describe pod/%s -n %s' to see all of the containers in this pod.", fullCmdName, o.PodName, o.Namespace) </del> <ins> if len(o.ParentCommandName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "describe") { o.EnableSuggestedCmdUsage = true </ins> } config, err := f.ToRESTConfig()

return nil, fmt.Errorf("container not found (%s)", o.ContainerName) } <del> if len(o.SuggestedCmdUsage) > 0 { </del> <ins> if o.EnableSuggestedCmdUsage { </ins> fmt.Fprintf(o.ErrOut, "Defaulting container name to %s.n", pod.Spec.Containers[0].Name) <del> fmt.Fprintf(o.ErrOut, "%sn", o.SuggestedCmdUsage) </del> <ins> fmt.Fprintf(o.ErrOut, "Use '%s describe pod/%s -n %s' to see all of the containers in this pod.n", o.ParentCommandName, o.PodName, o.Namespace) </ins> } klog.V(4).Infof("defaulting container name to %s", pod.Spec.Containers[0].Name)

ResourceName string Command      []string <del> FullCmdName       string SuggestedCmdUsage string </del> <ins> ParentCommandName       string EnableSuggestedCmdUsage bool </ins> Builder          func() *resource.Builder ExecutablePodFn  polymorphichelpers.AttachablePodForObjectFunc

cmdParent := cmd.Parent() if cmdParent != nil { <del> p.FullCmdName = cmdParent.CommandPath() </del> <ins> p.ParentCommandName = cmdParent.CommandPath() </ins> } <del> if len(p.FullCmdName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "describe") { p.SuggestedCmdUsage = fmt.Sprintf("Use '%s describe %s -n %s' to see all of the containers in this pod.", p.FullCmdName, p.ResourceName, p.Namespace) </del> <ins> if len(p.ParentCommandName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "describe") { p.EnableSuggestedCmdUsage = true </ins> } p.Config, err = f.ToRESTConfig()

containerName := p.ContainerName if len(containerName) == 0 { if len(pod.Spec.Containers) > 1 { <del> usageString := fmt.Sprintf("Defaulting container name to %s.", pod.Spec.Containers[0].Name) if len(p.SuggestedCmdUsage) > 0 { usageString = fmt.Sprintf("%sn%s", usageString, p.SuggestedCmdUsage) </del> <ins> fmt.Fprintf(p.ErrOut, "Defaulting container name to %s.n", pod.Spec.Containers[0].Name) if p.EnableSuggestedCmdUsage { fmt.Fprintf(p.ErrOut, "Use '%s describe pod/%s -n %s' to see all of the containers in this pod.n", p.ParentCommandName, pod.Name, p.Namespace) </ins> } <del> fmt.Fprintf(p.ErrOut, "%sn", usageString) </del> } containerName = pod.Spec.Containers[0].Name }