Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPSTREAM: 58533: add suggestion to describe pod for container names #18178

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/oc/cli/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ func (o *DebugOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args [
o.AsNonRoot = !o.AsRoot && cmd.Flag("as-root").Changed

if len(o.Attach.ContainerName) == 0 && len(pod.Spec.Containers) > 0 {
fullCmdName := ""
cmdParent := cmd.Parent()
if cmdParent != nil {
fullCmdName = cmdParent.CommandPath()
}

if len(fullCmdName) > 0 && kcmdutil.IsSiblingCommandExists(cmd, "describe") {
fmt.Fprintf(o.Attach.Err, "Defaulting container name to %s.\n", pod.Spec.Containers[0].Name)
fmt.Fprintf(o.Attach.Err, "Use '%s describe pod/%s -n %s' to see all of the containers in this pod.\n", fullCmdName, pod.Name, pod.Namespace)
}

glog.V(4).Infof("Defaulting container name to %s", pod.Spec.Containers[0].Name)
o.Attach.ContainerName = pod.Spec.Containers[0].Name
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/oc/cli/cmd/rsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ func (o *RshOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []s
o.PodClient = client.Core()

o.PodName, err = f.PodForResource(resource, time.Duration(o.Timeout)*time.Second)

fullCmdName := ""
cmdParent := cmd.Parent()
if cmdParent != nil {
fullCmdName = cmdParent.CommandPath()
}
if len(fullCmdName) > 0 && kcmdutil.IsSiblingCommandExists(cmd, "describe") {
o.ExecOptions.SuggestedCmdUsage = fmt.Sprintf("Use '%s describe pod/%s -n %s' to see all of the containers in this pod.", fullCmdName, o.PodName, o.Namespace)
}
return err
}

Expand Down
31 changes: 17 additions & 14 deletions pkg/oc/cli/cmd/rsync/execremote.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (

// remoteExecutor will execute commands on a given pod/container by using the kube Exec command
type remoteExecutor struct {
Namespace string
PodName string
ContainerName string
Client kclientset.Interface
Config *restclient.Config
Namespace string
PodName string
ContainerName string
SuggestedCmdUsage string
Client kclientset.Interface
Config *restclient.Config
}

// Ensure it implements the executor interface
Expand All @@ -37,10 +38,11 @@ func (e *remoteExecutor) Execute(command []string, in io.Reader, out, errOut io.
Err: errOut,
Stdin: in != nil,
},
Executor: &kubecmd.DefaultRemoteExecutor{},
PodClient: e.Client.Core(),
Config: e.Config,
Command: command,
SuggestedCmdUsage: e.SuggestedCmdUsage,
Executor: &kubecmd.DefaultRemoteExecutor{},
PodClient: e.Client.Core(),
Config: e.Config,
Command: command,
}
err := execOptions.Validate()
if err != nil {
Expand All @@ -66,10 +68,11 @@ func newRemoteExecutor(f *clientcmd.Factory, o *RsyncOptions) (executor, error)
}

return &remoteExecutor{
Namespace: o.Namespace,
PodName: o.PodName(),
ContainerName: o.ContainerName,
Config: config,
Client: client,
Namespace: o.Namespace,
PodName: o.PodName(),
ContainerName: o.ContainerName,
SuggestedCmdUsage: o.SuggestedCmdUsage,
Config: config,
Client: client,
}, nil
}
29 changes: 20 additions & 9 deletions pkg/oc/cli/cmd/rsync/rsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ type podChecker interface {

// RsyncOptions holds the options to execute the sync command
type RsyncOptions struct {
Namespace string
ContainerName string
Source *pathSpec
Destination *pathSpec
Strategy copyStrategy
StrategyName string
Quiet bool
Delete bool
Watch bool
Namespace string
ContainerName string
Source *pathSpec
Destination *pathSpec
Strategy copyStrategy
StrategyName string
Quiet bool
Delete bool
Watch bool
SuggestedCmdUsage string

RsyncInclude []string
RsyncExclude []string
Expand Down Expand Up @@ -214,6 +215,16 @@ func (o *RsyncOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args [
return err
}

fullCmdName := ""
cmdParent := cmd.Parent()
if cmdParent != nil {
fullCmdName = cmdParent.CommandPath()
}

if len(fullCmdName) > 0 && kcmdutil.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)
}

o.Strategy, err = o.determineStrategy(f, cmd, o.StrategyName)
if err != nil {
return err
Expand Down
17 changes: 16 additions & 1 deletion vendor/k8s.io/kubernetes/pkg/kubectl/cmd/attach.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.