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
ff4c1d80
Commit
ff4c1d80
authored
Mar 22, 2017
by
Avesh Agarwal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add validation for toleration annotations.
parent
ab5b462d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
helpers.go
pkg/api/helpers.go
+17
-0
validation.go
pkg/api/validation/validation.go
+21
-0
No files found.
pkg/api/helpers.go
View file @
ff4c1d80
...
@@ -430,6 +430,10 @@ func NodeSelectorRequirementsAsSelector(nsm []NodeSelectorRequirement) (labels.S
...
@@ -430,6 +430,10 @@ func NodeSelectorRequirementsAsSelector(nsm []NodeSelectorRequirement) (labels.S
}
}
const
(
const
(
// TolerationsAnnotationKey represents the key of tolerations data (json serialized)
// in the Annotations of a Pod.
TolerationsAnnotationKey
string
=
"scheduler.alpha.kubernetes.io/tolerations"
// SeccompPodAnnotationKey represents the key of a seccomp profile applied
// SeccompPodAnnotationKey represents the key of a seccomp profile applied
// to all containers of a pod.
// to all containers of a pod.
SeccompPodAnnotationKey
string
=
"seccomp.security.alpha.kubernetes.io/pod"
SeccompPodAnnotationKey
string
=
"seccomp.security.alpha.kubernetes.io/pod"
...
@@ -471,6 +475,19 @@ const (
...
@@ -471,6 +475,19 @@ const (
AffinityAnnotationKey
string
=
"scheduler.alpha.kubernetes.io/affinity"
AffinityAnnotationKey
string
=
"scheduler.alpha.kubernetes.io/affinity"
)
)
// GetTolerationsFromPodAnnotations gets the json serialized tolerations data from Pod.Annotations
// and converts it to the []Toleration type in api.
func
GetTolerationsFromPodAnnotations
(
annotations
map
[
string
]
string
)
([]
Toleration
,
error
)
{
var
tolerations
[]
Toleration
if
len
(
annotations
)
>
0
&&
annotations
[
TolerationsAnnotationKey
]
!=
""
{
err
:=
json
.
Unmarshal
([]
byte
(
annotations
[
TolerationsAnnotationKey
]),
&
tolerations
)
if
err
!=
nil
{
return
tolerations
,
err
}
}
return
tolerations
,
nil
}
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
// Returns true if something was updated, false otherwise.
// Returns true if something was updated, false otherwise.
func
AddOrUpdateTolerationInPod
(
pod
*
Pod
,
toleration
*
Toleration
)
(
bool
,
error
)
{
func
AddOrUpdateTolerationInPod
(
pod
*
Pod
,
toleration
*
Toleration
)
(
bool
,
error
)
{
...
...
pkg/api/validation/validation.go
View file @
ff4c1d80
...
@@ -109,6 +109,10 @@ func ValidatePodSpecificAnnotations(annotations map[string]string, spec *api.Pod
...
@@ -109,6 +109,10 @@ func ValidatePodSpecificAnnotations(annotations map[string]string, spec *api.Pod
allErrs
=
append
(
allErrs
,
ValidateAffinityInPodAnnotations
(
annotations
,
fldPath
)
...
)
allErrs
=
append
(
allErrs
,
ValidateAffinityInPodAnnotations
(
annotations
,
fldPath
)
...
)
}
}
if
annotations
[
api
.
TolerationsAnnotationKey
]
!=
""
{
allErrs
=
append
(
allErrs
,
ValidateTolerationsInPodAnnotations
(
annotations
,
fldPath
)
...
)
}
// TODO: remove these after we EOL the annotations.
// TODO: remove these after we EOL the annotations.
if
hostname
,
exists
:=
annotations
[
utilpod
.
PodHostnameAnnotation
];
exists
{
if
hostname
,
exists
:=
annotations
[
utilpod
.
PodHostnameAnnotation
];
exists
{
allErrs
=
append
(
allErrs
,
ValidateDNS1123Label
(
hostname
,
fldPath
.
Key
(
utilpod
.
PodHostnameAnnotation
))
...
)
allErrs
=
append
(
allErrs
,
ValidateDNS1123Label
(
hostname
,
fldPath
.
Key
(
utilpod
.
PodHostnameAnnotation
))
...
)
...
@@ -140,6 +144,23 @@ func ValidatePodSpecificAnnotations(annotations map[string]string, spec *api.Pod
...
@@ -140,6 +144,23 @@ func ValidatePodSpecificAnnotations(annotations map[string]string, spec *api.Pod
return
allErrs
return
allErrs
}
}
// ValidateTolerationsInPodAnnotations tests that the serialized tolerations in Pod.Annotations has valid data
func
ValidateTolerationsInPodAnnotations
(
annotations
map
[
string
]
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
tolerations
,
err
:=
api
.
GetTolerationsFromPodAnnotations
(
annotations
)
if
err
!=
nil
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
api
.
TolerationsAnnotationKey
,
err
.
Error
()))
return
allErrs
}
if
len
(
tolerations
)
>
0
{
allErrs
=
append
(
allErrs
,
validateTolerations
(
tolerations
,
fldPath
.
Child
(
api
.
TolerationsAnnotationKey
))
...
)
}
return
allErrs
}
// ValidateAffinityInPodAnnotations tests that the serialized Affinity in Pod.Annotations has valid data
// ValidateAffinityInPodAnnotations tests that the serialized Affinity in Pod.Annotations has valid data
func
ValidateAffinityInPodAnnotations
(
annotations
map
[
string
]
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
ValidateAffinityInPodAnnotations
(
annotations
map
[
string
]
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
allErrs
:=
field
.
ErrorList
{}
...
...
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