diff --git a/pkg/oc/cli/cmd/debug.go b/pkg/oc/cli/cmd/debug.go index de25e03ada56..af7e8628c21e 100644 --- a/pkg/oc/cli/cmd/debug.go +++ b/pkg/oc/cli/cmd/debug.go @@ -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 } diff --git a/pkg/oc/cli/cmd/rsh.go b/pkg/oc/cli/cmd/rsh.go index 0d622d748c34..b9f0fb85ae64 100644 --- a/pkg/oc/cli/cmd/rsh.go +++ b/pkg/oc/cli/cmd/rsh.go @@ -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 } diff --git a/pkg/oc/cli/cmd/rsync/execremote.go b/pkg/oc/cli/cmd/rsync/execremote.go index 93fbbcdabc5a..595f88afe983 100644 --- a/pkg/oc/cli/cmd/rsync/execremote.go +++ b/pkg/oc/cli/cmd/rsync/execremote.go @@ -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 @@ -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 { @@ -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 } diff --git a/pkg/oc/cli/cmd/rsync/rsync.go b/pkg/oc/cli/cmd/rsync/rsync.go index d6368b82d1dc..7476a7e0237b 100644 --- a/pkg/oc/cli/cmd/rsync/rsync.go +++ b/pkg/oc/cli/cmd/rsync/rsync.go @@ -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 @@ -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