mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Add label support for kubectl describe
Add -l option to kubectl describe command, allow it return multiple results filtered by label selector.
This commit is contained in:
parent
2c5d40a69e
commit
fa0efe3927
@ -275,6 +275,8 @@ _kubectl_describe()
|
|||||||
|
|
||||||
flags+=("--help")
|
flags+=("--help")
|
||||||
flags+=("-h")
|
flags+=("-h")
|
||||||
|
flags+=("--selector=")
|
||||||
|
two_word_flags+=("-l")
|
||||||
|
|
||||||
must_have_one_flag=()
|
must_have_one_flag=()
|
||||||
must_have_one_noun=()
|
must_have_one_noun=()
|
||||||
|
@ -22,12 +22,16 @@ $ kubectl describe nodes kubernetes-minion-emt8.c.myproject.internal
|
|||||||
|
|
||||||
// Describe a pod
|
// Describe a pod
|
||||||
$ kubectl describe pods/nginx
|
$ kubectl describe pods/nginx
|
||||||
|
|
||||||
|
// Describe pods by label name=myLabel
|
||||||
|
$ kubectl describe po -l name=myLabel
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
-h, --help=false: help for describe
|
-h, --help=false: help for describe
|
||||||
|
-l, --selector="": Selector (label query) to filter on
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options inherited from parent commands
|
### Options inherited from parent commands
|
||||||
@ -62,6 +66,6 @@ $ kubectl describe pods/nginx
|
|||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra at 2015-05-21 10:33:11.177122438 +0000 UTC
|
###### Auto generated by spf13/cobra at 2015-06-12 06:44:05.105790085 +0000 UTC
|
||||||
|
|
||||||
[]()
|
[]()
|
||||||
|
@ -25,6 +25,10 @@ given resource.
|
|||||||
\fB\-h\fP, \fB\-\-help\fP=false
|
\fB\-h\fP, \fB\-\-help\fP=false
|
||||||
help for describe
|
help for describe
|
||||||
|
|
||||||
|
.PP
|
||||||
|
\fB\-l\fP, \fB\-\-selector\fP=""
|
||||||
|
Selector (label query) to filter on
|
||||||
|
|
||||||
|
|
||||||
.SH OPTIONS INHERITED FROM PARENT COMMANDS
|
.SH OPTIONS INHERITED FROM PARENT COMMANDS
|
||||||
.PP
|
.PP
|
||||||
@ -135,6 +139,9 @@ $ kubectl describe nodes kubernetes\-minion\-emt8.c.myproject.internal
|
|||||||
// Describe a pod
|
// Describe a pod
|
||||||
$ kubectl describe pods/nginx
|
$ kubectl describe pods/nginx
|
||||||
|
|
||||||
|
// Describe pods by label name=myLabel
|
||||||
|
$ kubectl describe po \-l name=myLabel
|
||||||
|
|
||||||
.fi
|
.fi
|
||||||
.RE
|
.RE
|
||||||
|
|
||||||
|
@ -43,17 +43,22 @@ given resource.`,
|
|||||||
$ kubectl describe nodes kubernetes-minion-emt8.c.myproject.internal
|
$ kubectl describe nodes kubernetes-minion-emt8.c.myproject.internal
|
||||||
|
|
||||||
// Describe a pod
|
// Describe a pod
|
||||||
$ kubectl describe pods/nginx`,
|
$ kubectl describe pods/nginx
|
||||||
|
|
||||||
|
// Describe pods by label name=myLabel
|
||||||
|
$ kubectl describe po -l name=myLabel`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
err := RunDescribe(f, out, cmd, args)
|
err := RunDescribe(f, out, cmd, args)
|
||||||
cmdutil.CheckErr(err)
|
cmdutil.CheckErr(err)
|
||||||
},
|
},
|
||||||
ValidArgs: kubectl.DescribableResources(),
|
ValidArgs: kubectl.DescribableResources(),
|
||||||
}
|
}
|
||||||
|
cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
|
func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
|
||||||
|
selector := cmdutil.GetFlagString(cmd, "selector")
|
||||||
cmdNamespace, err := f.DefaultNamespace()
|
cmdNamespace, err := f.DefaultNamespace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -63,6 +68,7 @@ func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
|
|||||||
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
|
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
|
||||||
ContinueOnError().
|
ContinueOnError().
|
||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
NamespaceParam(cmdNamespace).DefaultNamespace().
|
||||||
|
SelectorParam(selector).
|
||||||
ResourceTypeOrNameArgs(false, args...).
|
ResourceTypeOrNameArgs(false, args...).
|
||||||
Flatten().
|
Flatten().
|
||||||
Do()
|
Do()
|
||||||
@ -86,16 +92,15 @@ func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(infos) > 1 {
|
|
||||||
return fmt.Errorf("multiple resources provided: %v", args)
|
|
||||||
}
|
|
||||||
info := infos[0]
|
|
||||||
|
|
||||||
s, err := describer.Describe(info.Namespace, info.Name)
|
for _, info := range infos {
|
||||||
if err != nil {
|
s, err := describer.Describe(info.Namespace, info.Name)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintf(out, "%s\n\n", s)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "%s\n", s)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
|
|||||||
t.Errorf("unexpected describer: %#v", d)
|
t.Errorf("unexpected describer: %#v", d)
|
||||||
}
|
}
|
||||||
|
|
||||||
if buf.String() != fmt.Sprintf("%s\n", d.Output) {
|
if buf.String() != fmt.Sprintf("%s\n\n", d.Output) {
|
||||||
t.Errorf("unexpected output: %s", buf.String())
|
t.Errorf("unexpected output: %s", buf.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user