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
6ff26d92
Commit
6ff26d92
authored
Jan 20, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3619 from smarterclayton/expose_validate_labels
Expose ValidateLabels in validation.go for reuse by other components
parents
fd52ba96
48146e01
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
10 deletions
+11
-10
validation.go
pkg/api/validation/validation.go
+9
-8
validation_test.go
pkg/api/validation/validation_test.go
+2
-2
No files found.
pkg/api/validation/validation.go
View file @
6ff26d92
...
@@ -378,7 +378,7 @@ func ValidatePod(pod *api.Pod) errs.ValidationErrorList {
...
@@ -378,7 +378,7 @@ func ValidatePod(pod *api.Pod) errs.ValidationErrorList {
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"namespace"
,
pod
.
Namespace
,
""
))
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"namespace"
,
pod
.
Namespace
,
""
))
}
}
allErrs
=
append
(
allErrs
,
ValidatePodSpec
(
&
pod
.
Spec
)
.
Prefix
(
"spec"
)
...
)
allErrs
=
append
(
allErrs
,
ValidatePodSpec
(
&
pod
.
Spec
)
.
Prefix
(
"spec"
)
...
)
allErrs
=
append
(
allErrs
,
v
alidateLabels
(
pod
.
Labels
,
"labels"
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateLabels
(
pod
.
Labels
,
"labels"
)
...
)
return
allErrs
return
allErrs
}
}
...
@@ -394,11 +394,12 @@ func ValidatePodSpec(spec *api.PodSpec) errs.ValidationErrorList {
...
@@ -394,11 +394,12 @@ func ValidatePodSpec(spec *api.PodSpec) errs.ValidationErrorList {
allErrs
=
append
(
allErrs
,
validateContainers
(
spec
.
Containers
,
allVolumes
)
.
Prefix
(
"containers"
)
...
)
allErrs
=
append
(
allErrs
,
validateContainers
(
spec
.
Containers
,
allVolumes
)
.
Prefix
(
"containers"
)
...
)
allErrs
=
append
(
allErrs
,
validateRestartPolicy
(
&
spec
.
RestartPolicy
)
.
Prefix
(
"restartPolicy"
)
...
)
allErrs
=
append
(
allErrs
,
validateRestartPolicy
(
&
spec
.
RestartPolicy
)
.
Prefix
(
"restartPolicy"
)
...
)
allErrs
=
append
(
allErrs
,
validateDNSPolicy
(
&
spec
.
DNSPolicy
)
.
Prefix
(
"dnsPolicy"
)
...
)
allErrs
=
append
(
allErrs
,
validateDNSPolicy
(
&
spec
.
DNSPolicy
)
.
Prefix
(
"dnsPolicy"
)
...
)
allErrs
=
append
(
allErrs
,
v
alidateLabels
(
spec
.
NodeSelector
,
"nodeSelector"
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateLabels
(
spec
.
NodeSelector
,
"nodeSelector"
)
...
)
return
allErrs
return
allErrs
}
}
func
validateLabels
(
labels
map
[
string
]
string
,
field
string
)
errs
.
ValidationErrorList
{
// ValidateLabels validates that a set of labels are correctly defined.
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
.
IsQualifiedName
(
k
)
{
if
!
util
.
IsQualifiedName
(
k
)
{
...
@@ -458,9 +459,9 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
...
@@ -458,9 +459,9 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
}
}
if
service
.
Spec
.
Selector
!=
nil
{
if
service
.
Spec
.
Selector
!=
nil
{
allErrs
=
append
(
allErrs
,
v
alidateLabels
(
service
.
Spec
.
Selector
,
"spec.selector"
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateLabels
(
service
.
Spec
.
Selector
,
"spec.selector"
)
...
)
}
}
allErrs
=
append
(
allErrs
,
v
alidateLabels
(
service
.
Labels
,
"labels"
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateLabels
(
service
.
Labels
,
"labels"
)
...
)
if
service
.
Spec
.
CreateExternalLoadBalancer
{
if
service
.
Spec
.
CreateExternalLoadBalancer
{
services
,
err
:=
lister
.
ListServices
(
ctx
)
services
,
err
:=
lister
.
ListServices
(
ctx
)
...
@@ -496,7 +497,7 @@ func ValidateReplicationController(controller *api.ReplicationController) errs.V
...
@@ -496,7 +497,7 @@ func ValidateReplicationController(controller *api.ReplicationController) errs.V
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"namespace"
,
controller
.
Namespace
,
""
))
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"namespace"
,
controller
.
Namespace
,
""
))
}
}
allErrs
=
append
(
allErrs
,
ValidateReplicationControllerSpec
(
&
controller
.
Spec
)
.
Prefix
(
"spec"
)
...
)
allErrs
=
append
(
allErrs
,
ValidateReplicationControllerSpec
(
&
controller
.
Spec
)
.
Prefix
(
"spec"
)
...
)
allErrs
=
append
(
allErrs
,
v
alidateLabels
(
controller
.
Labels
,
"labels"
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateLabels
(
controller
.
Labels
,
"labels"
)
...
)
return
allErrs
return
allErrs
}
}
...
@@ -533,7 +534,7 @@ func ValidateReplicationControllerSpec(spec *api.ReplicationControllerSpec) errs
...
@@ -533,7 +534,7 @@ func ValidateReplicationControllerSpec(spec *api.ReplicationControllerSpec) errs
// ValidatePodTemplateSpec validates the spec of a pod template
// ValidatePodTemplateSpec validates the spec of a pod template
func
ValidatePodTemplateSpec
(
spec
*
api
.
PodTemplateSpec
)
errs
.
ValidationErrorList
{
func
ValidatePodTemplateSpec
(
spec
*
api
.
PodTemplateSpec
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
=
append
(
allErrs
,
v
alidateLabels
(
spec
.
Labels
,
"labels"
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateLabels
(
spec
.
Labels
,
"labels"
)
...
)
allErrs
=
append
(
allErrs
,
ValidatePodSpec
(
&
spec
.
Spec
)
.
Prefix
(
"spec"
)
...
)
allErrs
=
append
(
allErrs
,
ValidatePodSpec
(
&
spec
.
Spec
)
.
Prefix
(
"spec"
)
...
)
allErrs
=
append
(
allErrs
,
ValidateReadOnlyPersistentDisks
(
spec
.
Spec
.
Volumes
)
.
Prefix
(
"spec.volumes"
)
...
)
allErrs
=
append
(
allErrs
,
ValidateReadOnlyPersistentDisks
(
spec
.
Spec
.
Volumes
)
.
Prefix
(
"spec.volumes"
)
...
)
return
allErrs
return
allErrs
...
@@ -577,7 +578,7 @@ func ValidateMinion(minion *api.Node) errs.ValidationErrorList {
...
@@ -577,7 +578,7 @@ func ValidateMinion(minion *api.Node) errs.ValidationErrorList {
if
len
(
minion
.
Name
)
==
0
{
if
len
(
minion
.
Name
)
==
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"name"
,
minion
.
Name
))
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"name"
,
minion
.
Name
))
}
}
allErrs
=
append
(
allErrs
,
v
alidateLabels
(
minion
.
Labels
,
"labels"
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateLabels
(
minion
.
Labels
,
"labels"
)
...
)
return
allErrs
return
allErrs
}
}
...
...
pkg/api/validation/validation_test.go
View file @
6ff26d92
...
@@ -53,7 +53,7 @@ func TestValidateLabels(t *testing.T) {
...
@@ -53,7 +53,7 @@ func TestValidateLabels(t *testing.T) {
{
"1.2.3.4/5678"
:
"bar"
},
{
"1.2.3.4/5678"
:
"bar"
},
}
}
for
i
:=
range
successCases
{
for
i
:=
range
successCases
{
errs
:=
v
alidateLabels
(
successCases
[
i
],
"field"
)
errs
:=
V
alidateLabels
(
successCases
[
i
],
"field"
)
if
len
(
errs
)
!=
0
{
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"case[%d] expected success, got %#v"
,
i
,
errs
)
t
.
Errorf
(
"case[%d] expected success, got %#v"
,
i
,
errs
)
}
}
...
@@ -67,7 +67,7 @@ func TestValidateLabels(t *testing.T) {
...
@@ -67,7 +67,7 @@ func TestValidateLabels(t *testing.T) {
{
strings
.
Repeat
(
"a"
,
254
)
:
"bar"
},
{
strings
.
Repeat
(
"a"
,
254
)
:
"bar"
},
}
}
for
i
:=
range
errorCases
{
for
i
:=
range
errorCases
{
errs
:=
v
alidateLabels
(
errorCases
[
i
],
"field"
)
errs
:=
V
alidateLabels
(
errorCases
[
i
],
"field"
)
if
len
(
errs
)
!=
1
{
if
len
(
errs
)
!=
1
{
t
.
Errorf
(
"case[%d] expected failure"
,
i
)
t
.
Errorf
(
"case[%d] expected failure"
,
i
)
}
}
...
...
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