Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
fb63ab63
Commit
fb63ab63
authored
May 20, 2015
by
kargakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
label: Invalidate empty or invalid value labels
parent
6fa2777e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
4 deletions
+16
-4
kubectl_label.md
docs/kubectl_label.md
+2
-1
kubectl-label.1
docs/man/man1/kubectl-label.1
+1
-0
label.go
pkg/kubectl/cmd/label.go
+5
-3
label_test.go
pkg/kubectl/cmd/label_test.go
+8
-0
No files found.
docs/kubectl_label.md
View file @
fb63ab63
...
@@ -7,6 +7,7 @@ Update the labels on a resource
...
@@ -7,6 +7,7 @@ Update the labels on a resource
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 --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.
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-
...
@@ -80,6 +81,6 @@ $ kubectl label pods foo bar-
### 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-2
1 10:33:11.210679161
+0000 UTC
###### Auto generated by spf13/cobra at 2015-05-2
8 08:44:48.996047458
+0000 UTC
[

]()
[

]()
docs/man/man1/kubectl-label.1
View file @
fb63ab63
...
@@ -16,6 +16,7 @@ kubectl label \- Update the labels on a resource
...
@@ -16,6 +16,7 @@ kubectl label \- Update the labels on a resource
Update the labels on a resource.
Update the labels on a resource.
.PP
.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 \-\-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.
If \-\-resource\-version is specified, then updates will use this resource version, otherwise the existing resource\-version will be used.
...
...
pkg/kubectl/cmd/label.go
View file @
fb63ab63
...
@@ -25,12 +25,14 @@ import (
...
@@ -25,12 +25,14 @@ import (
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
)
)
const
(
const
(
label_long
=
`Update the labels on a resource.
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 --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.`
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'.
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 {
...
@@ -54,7 +56,7 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"label [--overwrite] RESOURCE NAME KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]"
,
Use
:
"label [--overwrite] RESOURCE NAME KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]"
,
Short
:
"Update the labels on a resource"
,
Short
:
"Update the labels on a resource"
,
Long
:
label_long
,
Long
:
fmt
.
Sprintf
(
label_long
,
util
.
LabelValueMaxLength
)
,
Example
:
label_example
,
Example
:
label_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
RunLabel
(
f
,
out
,
cmd
,
args
)
err
:=
RunLabel
(
f
,
out
,
cmd
,
args
)
...
@@ -103,7 +105,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) {
...
@@ -103,7 +105,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) {
for
_
,
labelSpec
:=
range
spec
{
for
_
,
labelSpec
:=
range
spec
{
if
strings
.
Index
(
labelSpec
,
"="
)
!=
-
1
{
if
strings
.
Index
(
labelSpec
,
"="
)
!=
-
1
{
parts
:=
strings
.
Split
(
labelSpec
,
"="
)
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
)
return
nil
,
nil
,
fmt
.
Errorf
(
"invalid label spec: %v"
,
labelSpec
)
}
}
labels
[
parts
[
0
]]
=
parts
[
1
]
labels
[
parts
[
0
]]
=
parts
[
1
]
...
@@ -185,7 +187,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
...
@@ -185,7 +187,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
labels
,
remove
,
err
:=
parseLabels
(
labelArgs
)
labels
,
remove
,
err
:=
parseLabels
(
labelArgs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
cmdutil
.
UsageError
(
cmd
,
err
.
Error
())
}
}
mapper
,
typer
:=
f
.
Object
()
mapper
,
typer
:=
f
.
Object
()
...
...
pkg/kubectl/cmd/label_test.go
View file @
fb63ab63
...
@@ -125,6 +125,14 @@ func TestParseLabels(t *testing.T) {
...
@@ -125,6 +125,14 @@ func TestParseLabels(t *testing.T) {
labels
:
[]
string
{
"a=b"
,
"c=d"
,
"a-"
},
labels
:
[]
string
{
"a=b"
,
"c=d"
,
"a-"
},
expectErr
:
true
,
expectErr
:
true
,
},
},
{
labels
:
[]
string
{
"a="
},
expectErr
:
true
,
},
{
labels
:
[]
string
{
"a=%^$"
},
expectErr
:
true
,
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
labels
,
remove
,
err
:=
parseLabels
(
test
.
labels
)
labels
,
remove
,
err
:=
parseLabels
(
test
.
labels
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment