diff --git a/docs/kubectl_label.md b/docs/kubectl_label.md index 9897bdaa331..fa0bbaa83ec 100644 --- a/docs/kubectl_label.md +++ b/docs/kubectl_label.md @@ -7,6 +7,7 @@ Update the labels on a resource Update the labels on a resource. +A label must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to 63 characters. If --overwrite is true, then existing labels can be overwritten, otherwise attempting to overwrite a label will result in an error. If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used. @@ -80,6 +81,6 @@ $ kubectl label pods foo bar- ### SEE ALSO * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra at 2015-05-21 10:33:11.210679161 +0000 UTC +###### Auto generated by spf13/cobra at 2015-05-28 08:44:48.996047458 +0000 UTC [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_label.md?pixel)]() diff --git a/docs/man/man1/kubectl-label.1 b/docs/man/man1/kubectl-label.1 index fe7037eee90..9fddbcd4a07 100644 --- a/docs/man/man1/kubectl-label.1 +++ b/docs/man/man1/kubectl-label.1 @@ -16,6 +16,7 @@ kubectl label \- Update the labels on a resource Update the labels on a resource. .PP +A label must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to 63 characters. If \-\-overwrite is true, then existing labels can be overwritten, otherwise attempting to overwrite a label will result in an error. If \-\-resource\-version is specified, then updates will use this resource version, otherwise the existing resource\-version will be used. diff --git a/pkg/kubectl/cmd/label.go b/pkg/kubectl/cmd/label.go index 44648c39354..495607a10e2 100644 --- a/pkg/kubectl/cmd/label.go +++ b/pkg/kubectl/cmd/label.go @@ -25,12 +25,14 @@ import ( cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/spf13/cobra" ) const ( label_long = `Update the labels on a resource. +A label must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to %[1]d characters. If --overwrite is true, then existing labels can be overwritten, otherwise attempting to overwrite a label will result in an error. If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used.` label_example = `// Update pod 'foo' with the label 'unhealthy' and the value 'true'. @@ -54,7 +56,7 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "label [--overwrite] RESOURCE NAME KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]", Short: "Update the labels on a resource", - Long: label_long, + Long: fmt.Sprintf(label_long, util.LabelValueMaxLength), Example: label_example, Run: func(cmd *cobra.Command, args []string) { err := RunLabel(f, out, cmd, args) @@ -103,7 +105,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) { for _, labelSpec := range spec { if strings.Index(labelSpec, "=") != -1 { parts := strings.Split(labelSpec, "=") - if len(parts) != 2 { + if len(parts) != 2 || len(parts[1]) == 0 || !util.IsValidLabelValue(parts[1]) { return nil, nil, fmt.Errorf("invalid label spec: %v", labelSpec) } labels[parts[0]] = parts[1] @@ -185,7 +187,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri labels, remove, err := parseLabels(labelArgs) if err != nil { - return err + return cmdutil.UsageError(cmd, err.Error()) } mapper, typer := f.Object() diff --git a/pkg/kubectl/cmd/label_test.go b/pkg/kubectl/cmd/label_test.go index b59d91a8e9c..eb72e169237 100644 --- a/pkg/kubectl/cmd/label_test.go +++ b/pkg/kubectl/cmd/label_test.go @@ -125,6 +125,14 @@ func TestParseLabels(t *testing.T) { labels: []string{"a=b", "c=d", "a-"}, expectErr: true, }, + { + labels: []string{"a="}, + expectErr: true, + }, + { + labels: []string{"a=%^$"}, + expectErr: true, + }, } for _, test := range tests { labels, remove, err := parseLabels(test.labels)