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
0dad8dd4
Commit
0dad8dd4
authored
Aug 01, 2017
by
Avesh Agarwal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not allow empty topology key for pod affinities.
parent
5ce3b359
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
29 deletions
+49
-29
types.go
pkg/api/types.go
+1
-3
validation.go
pkg/api/validation/validation.go
+12
-19
validation_test.go
pkg/api/validation/validation_test.go
+36
-6
topologies.go
plugin/pkg/scheduler/algorithm/priorities/util/topologies.go
+0
-1
No files found.
pkg/api/types.go
View file @
0dad8dd4
...
...
@@ -2026,9 +2026,7 @@ type PodAffinityTerm struct {
// the labelSelector in the specified namespaces, where co-located is defined as running on a node
// whose value of the label with key topologyKey matches that of any node on which any of the
// selected pods is running.
// For PreferredDuringScheduling pod anti-affinity, empty topologyKey is interpreted as "all topologies"
// ("all topologies" here means all the topologyKeys indicated by scheduler command-line argument --failure-domains);
// for affinity and for RequiredDuringScheduling pod anti-affinity, empty topologyKey is not allowed.
// Empty topologyKey is not allowed.
// +optional
TopologyKey
string
}
...
...
pkg/api/validation/validation.go
View file @
0dad8dd4
...
...
@@ -2429,7 +2429,7 @@ func ValidatePreferredSchedulingTerms(terms []api.PreferredSchedulingTerm, fldPa
}
// validatePodAffinityTerm tests that the specified podAffinityTerm fields have valid data
func
validatePodAffinityTerm
(
podAffinityTerm
api
.
PodAffinityTerm
,
allowEmptyTopologyKey
bool
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
validatePodAffinityTerm
(
podAffinityTerm
api
.
PodAffinityTerm
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
allErrs
=
append
(
allErrs
,
unversionedvalidation
.
ValidateLabelSelector
(
podAffinityTerm
.
LabelSelector
,
fldPath
.
Child
(
"matchExpressions"
))
...
)
...
...
@@ -2438,32 +2438,29 @@ func validatePodAffinityTerm(podAffinityTerm api.PodAffinityTerm, allowEmptyTopo
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"namespace"
),
name
,
msg
))
}
}
if
!
allowEmptyTopologyKey
&&
len
(
podAffinityTerm
.
TopologyKey
)
==
0
{
allErrs
=
append
(
allErrs
,
field
.
Required
(
fldPath
.
Child
(
"topologyKey"
),
"can
only be empty for PreferredDuringScheduling pod anti affini
ty"
))
if
len
(
podAffinityTerm
.
TopologyKey
)
==
0
{
allErrs
=
append
(
allErrs
,
field
.
Required
(
fldPath
.
Child
(
"topologyKey"
),
"can
not be emp
ty"
))
}
if
len
(
podAffinityTerm
.
TopologyKey
)
!=
0
{
allErrs
=
append
(
allErrs
,
unversionedvalidation
.
ValidateLabelName
(
podAffinityTerm
.
TopologyKey
,
fldPath
.
Child
(
"topologyKey"
))
...
)
}
return
allErrs
return
append
(
allErrs
,
unversionedvalidation
.
ValidateLabelName
(
podAffinityTerm
.
TopologyKey
,
fldPath
.
Child
(
"topologyKey"
))
...
)
}
// validatePodAffinityTerms tests that the specified podAffinityTerms fields have valid data
func
validatePodAffinityTerms
(
podAffinityTerms
[]
api
.
PodAffinityTerm
,
allowEmptyTopologyKey
bool
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
validatePodAffinityTerms
(
podAffinityTerms
[]
api
.
PodAffinityTerm
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
for
i
,
podAffinityTerm
:=
range
podAffinityTerms
{
allErrs
=
append
(
allErrs
,
validatePodAffinityTerm
(
podAffinityTerm
,
allowEmptyTopologyKey
,
fldPath
.
Index
(
i
))
...
)
allErrs
=
append
(
allErrs
,
validatePodAffinityTerm
(
podAffinityTerm
,
fldPath
.
Index
(
i
))
...
)
}
return
allErrs
}
// validateWeightedPodAffinityTerms tests that the specified weightedPodAffinityTerms fields have valid data
func
validateWeightedPodAffinityTerms
(
weightedPodAffinityTerms
[]
api
.
WeightedPodAffinityTerm
,
allowEmptyTopologyKey
bool
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
validateWeightedPodAffinityTerms
(
weightedPodAffinityTerms
[]
api
.
WeightedPodAffinityTerm
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
for
j
,
weightedTerm
:=
range
weightedPodAffinityTerms
{
if
weightedTerm
.
Weight
<=
0
||
weightedTerm
.
Weight
>
100
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Index
(
j
)
.
Child
(
"weight"
),
weightedTerm
.
Weight
,
"must be in the range 1-100"
))
}
allErrs
=
append
(
allErrs
,
validatePodAffinityTerm
(
weightedTerm
.
PodAffinityTerm
,
allowEmptyTopologyKey
,
fldPath
.
Index
(
j
)
.
Child
(
"podAffinityTerm"
))
...
)
allErrs
=
append
(
allErrs
,
validatePodAffinityTerm
(
weightedTerm
.
PodAffinityTerm
,
fldPath
.
Index
(
j
)
.
Child
(
"podAffinityTerm"
))
...
)
}
return
allErrs
}
...
...
@@ -2477,13 +2474,11 @@ func validatePodAntiAffinity(podAntiAffinity *api.PodAntiAffinity, fldPath *fiel
// fldPath.Child("requiredDuringSchedulingRequiredDuringExecution"))...)
//}
if
podAntiAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
!=
nil
{
// empty topologyKey is not allowed for hard pod anti-affinity
allErrs
=
append
(
allErrs
,
validatePodAffinityTerms
(
podAntiAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
,
false
,
allErrs
=
append
(
allErrs
,
validatePodAffinityTerms
(
podAntiAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
,
fldPath
.
Child
(
"requiredDuringSchedulingIgnoredDuringExecution"
))
...
)
}
if
podAntiAffinity
.
PreferredDuringSchedulingIgnoredDuringExecution
!=
nil
{
// empty topologyKey is allowed for soft pod anti-affinity
allErrs
=
append
(
allErrs
,
validateWeightedPodAffinityTerms
(
podAntiAffinity
.
PreferredDuringSchedulingIgnoredDuringExecution
,
true
,
allErrs
=
append
(
allErrs
,
validateWeightedPodAffinityTerms
(
podAntiAffinity
.
PreferredDuringSchedulingIgnoredDuringExecution
,
fldPath
.
Child
(
"preferredDuringSchedulingIgnoredDuringExecution"
))
...
)
}
return
allErrs
...
...
@@ -2498,13 +2493,11 @@ func validatePodAffinity(podAffinity *api.PodAffinity, fldPath *field.Path) fiel
// fldPath.Child("requiredDuringSchedulingRequiredDuringExecution"))...)
//}
if
podAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
!=
nil
{
// empty topologyKey is not allowed for hard pod affinity
allErrs
=
append
(
allErrs
,
validatePodAffinityTerms
(
podAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
,
false
,
allErrs
=
append
(
allErrs
,
validatePodAffinityTerms
(
podAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
,
fldPath
.
Child
(
"requiredDuringSchedulingIgnoredDuringExecution"
))
...
)
}
if
podAffinity
.
PreferredDuringSchedulingIgnoredDuringExecution
!=
nil
{
// empty topologyKey is not allowed for soft pod affinity
allErrs
=
append
(
allErrs
,
validateWeightedPodAffinityTerms
(
podAffinity
.
PreferredDuringSchedulingIgnoredDuringExecution
,
false
,
allErrs
=
append
(
allErrs
,
validateWeightedPodAffinityTerms
(
podAffinity
.
PreferredDuringSchedulingIgnoredDuringExecution
,
fldPath
.
Child
(
"preferredDuringSchedulingIgnoredDuringExecution"
))
...
)
}
return
allErrs
...
...
pkg/api/validation/validation_test.go
View file @
0dad8dd4
...
...
@@ -4655,8 +4655,8 @@ func TestValidatePod(t *testing.T) {
}),
},
},
"invalid pod affinity, empty topologyKey is not allowed for hard pod affinity"
:
{
expectedError
:
"can
only be empty for PreferredDuringScheduling pod anti affini
ty"
,
"invalid
hard
pod affinity, empty topologyKey is not allowed for hard pod affinity"
:
{
expectedError
:
"can
not be emp
ty"
,
spec
:
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"123"
,
...
...
@@ -4682,8 +4682,8 @@ func TestValidatePod(t *testing.T) {
}),
},
},
"invalid pod anti-affinity, empty topologyKey is not allowed for hard pod anti-affinity"
:
{
expectedError
:
"can
only be empty for PreferredDuringScheduling pod anti affini
ty"
,
"invalid
hard
pod anti-affinity, empty topologyKey is not allowed for hard pod anti-affinity"
:
{
expectedError
:
"can
not be emp
ty"
,
spec
:
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"123"
,
...
...
@@ -4709,8 +4709,8 @@ func TestValidatePod(t *testing.T) {
}),
},
},
"invalid
pod anti-
affinity, empty topologyKey is not allowed for soft pod affinity"
:
{
expectedError
:
"can
only be empty for PreferredDuringScheduling pod anti affini
ty"
,
"invalid
soft pod
affinity, empty topologyKey is not allowed for soft pod affinity"
:
{
expectedError
:
"can
not be emp
ty"
,
spec
:
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"123"
,
...
...
@@ -4739,6 +4739,36 @@ func TestValidatePod(t *testing.T) {
}),
},
},
"invalid soft pod anti-affinity, empty topologyKey is not allowed for soft pod anti-affinity"
:
{
expectedError
:
"can not be empty"
,
spec
:
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"123"
,
Namespace
:
"ns"
,
},
Spec
:
validPodSpec
(
&
api
.
Affinity
{
PodAntiAffinity
:
&
api
.
PodAntiAffinity
{
PreferredDuringSchedulingIgnoredDuringExecution
:
[]
api
.
WeightedPodAffinityTerm
{
{
Weight
:
10
,
PodAffinityTerm
:
api
.
PodAffinityTerm
{
LabelSelector
:
&
metav1
.
LabelSelector
{
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{
{
Key
:
"key2"
,
Operator
:
metav1
.
LabelSelectorOpNotIn
,
Values
:
[]
string
{
"value1"
,
"value2"
},
},
},
},
Namespaces
:
[]
string
{
"ns"
},
},
},
},
},
}),
},
},
"invalid toleration key"
:
{
expectedError
:
"spec.tolerations[0].key"
,
spec
:
api
.
Pod
{
...
...
plugin/pkg/scheduler/algorithm/priorities/util/topologies.go
View file @
0dad8dd4
...
...
@@ -75,7 +75,6 @@ type Topologies struct {
}
// NodesHaveSameTopologyKey checks if nodeA and nodeB have same label value with given topologyKey as label key.
// If the topologyKey is empty, check if the two nodes have any of the default topologyKeys, and have same corresponding label value.
func
(
tps
*
Topologies
)
NodesHaveSameTopologyKey
(
nodeA
,
nodeB
*
v1
.
Node
,
topologyKey
string
)
bool
{
return
NodesHaveSameTopologyKey
(
nodeA
,
nodeB
,
topologyKey
)
}
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