mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
add suggestion to use describe
to obtain container names
This commit is contained in:
parent
e4424b8a04
commit
f8cc2ab3b8
@ -287,7 +287,7 @@ Find more information at https://github.com/kubernetes/kubernetes.`,
|
||||
NewCmdDescribe(f, out, err),
|
||||
NewCmdLogs(f, out),
|
||||
NewCmdAttach(f, in, out, err),
|
||||
NewCmdExec(f, in, out, err),
|
||||
NewCmdExec("kubectl", f, in, out, err),
|
||||
NewCmdPortForward(f, out, err),
|
||||
NewCmdProxy(f, out),
|
||||
},
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"net/url"
|
||||
|
||||
dockerterm "github.com/docker/docker/pkg/term"
|
||||
"github.com/golang/glog"
|
||||
"github.com/renstrom/dedent"
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@ -52,7 +51,7 @@ const (
|
||||
execUsageStr = "expected 'exec POD_NAME COMMAND [ARG1] [ARG2] ... [ARGN]'.\nPOD_NAME and COMMAND are required arguments for the exec command"
|
||||
)
|
||||
|
||||
func NewCmdExec(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {
|
||||
func NewCmdExec(cmdFullName string, f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {
|
||||
options := &ExecOptions{
|
||||
StreamOptions: StreamOptions{
|
||||
In: cmdIn,
|
||||
@ -60,6 +59,7 @@ func NewCmdExec(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *
|
||||
Err: cmdErr,
|
||||
},
|
||||
|
||||
FullCmdName: cmdFullName,
|
||||
Executor: &DefaultRemoteExecutor{},
|
||||
}
|
||||
cmd := &cobra.Command{
|
||||
@ -130,6 +130,7 @@ type ExecOptions struct {
|
||||
|
||||
Command []string
|
||||
|
||||
FullCmdName string
|
||||
Executor RemoteExecutor
|
||||
Client *client.Client
|
||||
Config *restclient.Config
|
||||
@ -137,6 +138,10 @@ type ExecOptions struct {
|
||||
|
||||
// Complete verifies command line arguments and loads data from the command environment
|
||||
func (p *ExecOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn []string, argsLenAtDash int) error {
|
||||
if len(p.FullCmdName) == 0 {
|
||||
p.FullCmdName = "kubectl"
|
||||
}
|
||||
|
||||
// Let kubectl exec follow rules for `--`, see #13004 issue
|
||||
if len(p.PodName) == 0 && (len(argsIn) == 0 || argsLenAtDash == 0) {
|
||||
return cmdutil.UsageError(cmd, execUsageStr)
|
||||
@ -258,7 +263,9 @@ func (p *ExecOptions) Run() error {
|
||||
|
||||
containerName := p.ContainerName
|
||||
if len(containerName) == 0 {
|
||||
glog.V(4).Infof("defaulting container name to %s", pod.Spec.Containers[0].Name)
|
||||
if len(pod.Spec.Containers) > 1 {
|
||||
fmt.Fprintf(p.Err, "defaulting container name to %s, use '%s describe pod/%s' to see all container names\n", pod.Spec.Containers[0].Name, p.FullCmdName, p.PodName)
|
||||
}
|
||||
containerName = pod.Spec.Containers[0].Name
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user