mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 13:55:41 +00:00
Merge pull request #58533 from juanvallejo/jvallejo/usability-add-kubectl-describe-suggestion
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. suggest using describe cmd to list pod containers **Release note**: ```release-note NONE ``` Usability: suggest using `kubectl describe` to obtain available pod containers when running `kubectl attach ...` cc @soltysh
This commit is contained in:
commit
5320cdeedd
@ -116,6 +116,7 @@ type AttachOptions struct {
|
|||||||
StreamOptions
|
StreamOptions
|
||||||
|
|
||||||
CommandName string
|
CommandName string
|
||||||
|
SuggestedCmdUsage string
|
||||||
|
|
||||||
Pod *api.Pod
|
Pod *api.Pod
|
||||||
|
|
||||||
@ -168,6 +169,15 @@ func (p *AttachOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn [
|
|||||||
p.PodName = attachablePod.Name
|
p.PodName = attachablePod.Name
|
||||||
p.Namespace = namespace
|
p.Namespace = namespace
|
||||||
|
|
||||||
|
fullCmdName := ""
|
||||||
|
cmdParent := cmd.Parent()
|
||||||
|
if cmdParent != nil {
|
||||||
|
fullCmdName = cmdParent.CommandPath()
|
||||||
|
}
|
||||||
|
if len(fullCmdName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "describe") {
|
||||||
|
p.SuggestedCmdUsage = fmt.Sprintf("Use '%s describe pod/%s -n %s' to see all of the containers in this pod.", fullCmdName, p.PodName, p.Namespace)
|
||||||
|
}
|
||||||
|
|
||||||
config, err := f.ClientConfig()
|
config, err := f.ClientConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -311,6 +321,11 @@ func (p *AttachOptions) containerToAttachTo(pod *api.Pod) (*api.Container, error
|
|||||||
return nil, fmt.Errorf("container not found (%s)", p.ContainerName)
|
return nil, fmt.Errorf("container not found (%s)", p.ContainerName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(p.SuggestedCmdUsage) > 0 {
|
||||||
|
fmt.Fprintf(p.Err, "Defaulting container name to %s.\n", pod.Spec.Containers[0].Name)
|
||||||
|
fmt.Fprintf(p.Err, "%s\n", p.SuggestedCmdUsage)
|
||||||
|
}
|
||||||
|
|
||||||
glog.V(4).Infof("defaulting container name to %s", pod.Spec.Containers[0].Name)
|
glog.V(4).Infof("defaulting container name to %s", pod.Spec.Containers[0].Name)
|
||||||
return &pod.Spec.Containers[0], nil
|
return &pod.Spec.Containers[0], nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user