Skip to content

Commit

Permalink
add suggestion to describe pod for container names
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Jan 19, 2018
1 parent f3d0418 commit 45da559
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
10 changes: 10 additions & 0 deletions pkg/oc/cli/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ 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, "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.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

0 comments on commit 45da559

Please sign in to comment.