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
c857dc11
Commit
c857dc11
authored
Nov 20, 2014
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add namespacing for label keys
parent
d5a6a543
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
3 deletions
+57
-3
types.go
pkg/api/types.go
+10
-1
validation.go
pkg/api/validation/validation.go
+14
-2
validation_test.go
pkg/api/validation/validation_test.go
+33
-0
No files found.
pkg/api/types.go
View file @
c857dc11
...
@@ -107,12 +107,21 @@ type ObjectMeta struct {
...
@@ -107,12 +107,21 @@ type ObjectMeta struct {
CreationTimestamp
util
.
Time
`json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"`
CreationTimestamp
util
.
Time
`json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"`
// Labels are key value pairs that may be used to scope and select individual resources.
// Labels are key value pairs that may be used to scope and select individual resources.
// Label keys are of the form:
// label-key ::= prefixed-name | name
// prefixed-name ::= prefix '/' name
// prefix ::= DNS_SUBDOMAIN
// name ::= DNS_LABEL
// The prefix is optional. If the prefix is not specified, the key is assumed to be private
// to the user. Other system components that wish to use labels must specify a prefix. The
// "kubernetes.io/" prefix is reserved for use by kubernetes components.
// TODO: replace map[string]string with labels.LabelSet type
// TODO: replace map[string]string with labels.LabelSet type
Labels
map
[
string
]
string
`json:"labels,omitempty" yaml:"labels,omitempty"`
Labels
map
[
string
]
string
`json:"labels,omitempty" yaml:"labels,omitempty"`
// Annotations are unstructured key value data stored with a resource that may be set by
// Annotations are unstructured key value data stored with a resource that may be set by
// external tooling. They are not queryable and should be preserved when modifying
// external tooling. They are not queryable and should be preserved when modifying
// objects.
// objects. Annotation keys have the same formatting restrictions as Label keys. See the
// comments on Labels for details.
Annotations
map
[
string
]
string
`json:"annotations,omitempty" yaml:"annotations,omitempty"`
Annotations
map
[
string
]
string
`json:"annotations,omitempty" yaml:"annotations,omitempty"`
}
}
...
...
pkg/api/validation/validation.go
View file @
c857dc11
...
@@ -385,8 +385,20 @@ func ValidatePodSpec(spec *api.PodSpec) errs.ValidationErrorList {
...
@@ -385,8 +385,20 @@ func ValidatePodSpec(spec *api.PodSpec) errs.ValidationErrorList {
func
validateLabels
(
labels
map
[
string
]
string
,
field
string
)
errs
.
ValidationErrorList
{
func
validateLabels
(
labels
map
[
string
]
string
,
field
string
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
:=
errs
.
ValidationErrorList
{}
for
k
:=
range
labels
{
for
k
:=
range
labels
{
if
!
util
.
IsDNS952Label
(
k
)
{
var
n
,
ns
string
allErrs
=
append
(
allErrs
,
errs
.
NewFieldNotSupported
(
field
,
k
))
parts
:=
strings
.
Split
(
k
,
"/"
)
switch
len
(
parts
)
{
case
1
:
n
=
parts
[
0
]
case
2
:
ns
=
parts
[
0
]
n
=
parts
[
1
]
default
:
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
field
,
k
,
""
))
continue
}
if
(
ns
!=
""
&&
!
util
.
IsDNSSubdomain
(
ns
))
||
!
util
.
IsDNS952Label
(
n
)
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
field
,
k
,
""
))
}
}
}
}
return
allErrs
return
allErrs
...
...
pkg/api/validation/validation_test.go
View file @
c857dc11
...
@@ -35,6 +35,39 @@ func expectPrefix(t *testing.T, prefix string, errs errors.ValidationErrorList)
...
@@ -35,6 +35,39 @@ func expectPrefix(t *testing.T, prefix string, errs errors.ValidationErrorList)
}
}
}
}
func
TestValidateLabels
(
t
*
testing
.
T
)
{
successCases
:=
[]
map
[
string
]
string
{
{
"simple"
:
"bar"
},
{
"now-with-dashes"
:
"bar"
},
{
"simple/simple"
:
"bar"
},
{
"now-with-dashes/simple"
:
"bar"
},
{
"now-with-dashes/now-with-dashes"
:
"bar"
},
{
"now.with.dots/simple"
:
"bar"
},
{
"now-with.dashes-and.dots/simple"
:
"bar"
},
}
for
i
:=
range
successCases
{
errs
:=
validateLabels
(
successCases
[
i
],
"field"
)
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"case[%d] expected success, got %#v"
,
i
,
errs
)
}
}
errorCases
:=
[]
map
[
string
]
string
{
{
"123cantbeginwithnumber"
:
"bar"
},
//invalid
{
"NoUppercase123"
:
"bar"
},
//invalid
{
"nospecialchars^=@"
:
"bar"
},
//invalid
{
"cantendwithadash-"
:
"bar"
},
//invalid
{
"rfc952-mustbe24charactersorless"
:
"bar"
},
//invalid
{
"only/one/slash"
:
"bar"
},
}
for
i
:=
range
errorCases
{
errs
:=
validateLabels
(
errorCases
[
i
],
"field"
)
if
len
(
errs
)
!=
1
{
t
.
Errorf
(
"case[%d] expected failure"
,
i
)
}
}
}
func
TestValidateVolumes
(
t
*
testing
.
T
)
{
func
TestValidateVolumes
(
t
*
testing
.
T
)
{
successCase
:=
[]
api
.
Volume
{
successCase
:=
[]
api
.
Volume
{
{
Name
:
"abc"
},
{
Name
:
"abc"
},
...
...
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