Unverified Commit 5286806a authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #58353 from juanvallejo/jvallejo/usability-fix-label

Automatic merge from submit-queue (batch tested with PRs 61487, 58353, 61078, 61219, 60792). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. distinguish which labels belong to resource **Release note**: ```release-note NONE ``` Usability improvement for `kubectl label ... --list` when listing labels for more than one resource. Append resource kind/name before its set of labels. **Before** ``` $ kubectl label dc myapp test-deployment-config label1=test --list app=myapp label1=test label1=test ``` **After** ``` $ kubectl label dc myapp test-deployment-config label1=test --list Listing labels for DeploymentConfig/myapp: label1=test app=myapp Listing labels for DeploymentConfig/test-deployment-config: label1=test ```
parents 4f0ec7b1 d1cb6e36
...@@ -310,7 +310,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob ...@@ -310,7 +310,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
{ {
Message: "Settings Commands:", Message: "Settings Commands:",
Commands: []*cobra.Command{ Commands: []*cobra.Command{
NewCmdLabel(f, out), NewCmdLabel(f, out, err),
NewCmdAnnotate(f, out), NewCmdAnnotate(f, out),
NewCmdCompletion(out, ""), NewCmdCompletion(out, ""),
}, },
......
...@@ -62,7 +62,8 @@ type LabelOptions struct { ...@@ -62,7 +62,8 @@ type LabelOptions struct {
removeLabels []string removeLabels []string
// Common shared fields // Common shared fields
out io.Writer out io.Writer
errout io.Writer
} }
var ( var (
...@@ -95,8 +96,11 @@ var ( ...@@ -95,8 +96,11 @@ var (
kubectl label pods foo bar-`)) kubectl label pods foo bar-`))
) )
func NewCmdLabel(f cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdLabel(f cmdutil.Factory, out, errout io.Writer) *cobra.Command {
options := &LabelOptions{} options := &LabelOptions{
errout: errout,
}
validArgs := cmdutil.ValidArgList(f) validArgs := cmdutil.ValidArgList(f)
cmd := &cobra.Command{ cmd := &cobra.Command{
...@@ -280,8 +284,13 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error { ...@@ -280,8 +284,13 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
return err return err
} }
indent := ""
if !one {
indent = " "
fmt.Fprintf(o.errout, "Listing labels for %s.%s/%s:\n", info.Mapping.GroupVersionKind.Kind, info.Mapping.GroupVersionKind.Group, info.Name)
}
for k, v := range accessor.GetLabels() { for k, v := range accessor.GetLabels() {
fmt.Fprintf(o.out, "%s=%s\n", k, v) fmt.Fprintf(o.out, "%s%s=%s\n", indent, k, v)
} }
return nil return nil
......
...@@ -329,7 +329,7 @@ func TestLabelErrors(t *testing.T) { ...@@ -329,7 +329,7 @@ func TestLabelErrors(t *testing.T) {
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(tf, buf) cmd := NewCmdLabel(tf, buf, buf)
cmd.SetOutput(buf) cmd.SetOutput(buf)
for k, v := range testCase.flags { for k, v := range testCase.flags {
...@@ -391,7 +391,7 @@ func TestLabelForResourceFromFile(t *testing.T) { ...@@ -391,7 +391,7 @@ func TestLabelForResourceFromFile(t *testing.T) {
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(tf, buf) cmd := NewCmdLabel(tf, buf, buf)
opts := LabelOptions{FilenameOptions: resource.FilenameOptions{ opts := LabelOptions{FilenameOptions: resource.FilenameOptions{
Filenames: []string{"../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}}} Filenames: []string{"../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}}}
err := opts.Complete(buf, cmd, []string{"a=b"}) err := opts.Complete(buf, cmd, []string{"a=b"})
...@@ -424,7 +424,7 @@ func TestLabelLocal(t *testing.T) { ...@@ -424,7 +424,7 @@ func TestLabelLocal(t *testing.T) {
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(tf, buf) cmd := NewCmdLabel(tf, buf, buf)
opts := LabelOptions{FilenameOptions: resource.FilenameOptions{ opts := LabelOptions{FilenameOptions: resource.FilenameOptions{
Filenames: []string{"../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}}, Filenames: []string{"../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}},
local: true} local: true}
...@@ -482,8 +482,8 @@ func TestLabelMultipleObjects(t *testing.T) { ...@@ -482,8 +482,8 @@ func TestLabelMultipleObjects(t *testing.T) {
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(tf, buf)
opts := LabelOptions{all: true} opts := LabelOptions{all: true}
cmd := NewCmdLabel(tf, buf, buf)
err := opts.Complete(buf, cmd, []string{"pods", "a=b"}) err := opts.Complete(buf, cmd, []string{"pods", "a=b"})
if err == nil { if err == nil {
err = opts.Validate() err = opts.Validate()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment