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
ab5b462d
Commit
ab5b462d
authored
Mar 22, 2017
by
Avesh Agarwal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add node affinity, pod affinity and pod antiaffinity validation for alpha annotations.
parent
321acf00
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
helpers.go
pkg/api/helpers.go
+21
-0
validation.go
pkg/api/validation/validation.go
+21
-0
No files found.
pkg/api/helpers.go
View file @
ab5b462d
...
...
@@ -18,6 +18,7 @@ package api
import
(
"crypto/md5"
"encoding/json"
"fmt"
"reflect"
"strings"
...
...
@@ -463,6 +464,11 @@ const (
// an object (e.g. secret, config map) before fetching it again from apiserver.
// This annotation can be attached to node.
ObjectTTLAnnotationKey
string
=
"node.alpha.kubernetes.io/ttl"
// AffinityAnnotationKey represents the key of affinity data (json serialized)
// in the Annotations of a Pod.
// TODO: remove when alpha support for affinity is removed
AffinityAnnotationKey
string
=
"scheduler.alpha.kubernetes.io/affinity"
)
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
...
...
@@ -596,6 +602,21 @@ func PodAnnotationsFromSysctls(sysctls []Sysctl) string {
return
strings
.
Join
(
kvs
,
","
)
}
// GetAffinityFromPodAnnotations gets the json serialized affinity data from Pod.Annotations
// and converts it to the Affinity type in api.
// TODO: remove when alpha support for affinity is removed
func
GetAffinityFromPodAnnotations
(
annotations
map
[
string
]
string
)
(
*
Affinity
,
error
)
{
if
len
(
annotations
)
>
0
&&
annotations
[
AffinityAnnotationKey
]
!=
""
{
var
affinity
Affinity
err
:=
json
.
Unmarshal
([]
byte
(
annotations
[
AffinityAnnotationKey
]),
&
affinity
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
affinity
,
nil
}
return
nil
,
nil
}
// GetPersistentVolumeClass returns StorageClassName.
func
GetPersistentVolumeClass
(
volume
*
PersistentVolume
)
string
{
// Use beta annotation first
...
...
pkg/api/validation/validation.go
View file @
ab5b462d
...
...
@@ -105,6 +105,10 @@ func ValidateDNS1123Subdomain(value string, fldPath *field.Path) field.ErrorList
func
ValidatePodSpecificAnnotations
(
annotations
map
[
string
]
string
,
spec
*
api
.
PodSpec
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
if
annotations
[
api
.
AffinityAnnotationKey
]
!=
""
{
allErrs
=
append
(
allErrs
,
ValidateAffinityInPodAnnotations
(
annotations
,
fldPath
)
...
)
}
// TODO: remove these after we EOL the annotations.
if
hostname
,
exists
:=
annotations
[
utilpod
.
PodHostnameAnnotation
];
exists
{
allErrs
=
append
(
allErrs
,
ValidateDNS1123Label
(
hostname
,
fldPath
.
Key
(
utilpod
.
PodHostnameAnnotation
))
...
)
...
...
@@ -136,6 +140,23 @@ func ValidatePodSpecificAnnotations(annotations map[string]string, spec *api.Pod
return
allErrs
}
// ValidateAffinityInPodAnnotations tests that the serialized Affinity in Pod.Annotations has valid data
func
ValidateAffinityInPodAnnotations
(
annotations
map
[
string
]
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
affinity
,
err
:=
api
.
GetAffinityFromPodAnnotations
(
annotations
)
if
err
!=
nil
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
api
.
AffinityAnnotationKey
,
err
.
Error
()))
return
allErrs
}
if
affinity
==
nil
{
return
allErrs
}
allErrs
=
append
(
allErrs
,
validateAffinity
(
affinity
,
fldPath
.
Child
(
"affinity"
))
...
)
return
allErrs
}
func
ValidatePodSpecificAnnotationUpdates
(
newPod
,
oldPod
*
api
.
Pod
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
newAnnotations
:=
newPod
.
Annotations
...
...
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