Skip to content

Commit 084715a

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #62448 from k82cn/k8s_62002
Automatic merge from submit-queue (batch tested with PRs 62448, 59317, 59947, 62418, 62352). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Removed no-empty validation of nodeSelectorTerm.matchExpressions. Signed-off-by: Da K. Ma <klaus1982.cn@gmail.com> **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: part of #62002 **Release note**: ```release-note Pod affinity `nodeSelectorTerm.matchExpressions` may now be empty, and works as previously documented: nil or empty `matchExpressions` matches no objects in scheduler. ```
2 parents 74c6632 + d8e6dbf commit 084715a

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

pkg/apis/core/validation/validation.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,9 +3005,6 @@ func ValidateNodeSelectorRequirement(rq core.NodeSelectorRequirement, fldPath *f
30053005
func ValidateNodeSelectorTerm(term core.NodeSelectorTerm, fldPath *field.Path) field.ErrorList {
30063006
allErrs := field.ErrorList{}
30073007

3008-
if len(term.MatchExpressions) == 0 {
3009-
return append(allErrs, field.Required(fldPath.Child("matchExpressions"), "must have at least one node selector requirement"))
3010-
}
30113008
for j, req := range term.MatchExpressions {
30123009
allErrs = append(allErrs, ValidateNodeSelectorRequirement(req, fldPath.Child("matchExpressions").Index(j))...)
30133010
}

pkg/apis/core/validation/validation_test.go

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6069,6 +6069,47 @@ func TestValidatePod(t *testing.T) {
60696069
},
60706070
),
60716071
},
6072+
{ // Serialized node affinity requirements.
6073+
ObjectMeta: metav1.ObjectMeta{
6074+
Name: "123",
6075+
Namespace: "ns",
6076+
},
6077+
Spec: validPodSpec(
6078+
// TODO: Uncomment and move this block and move inside NodeAffinity once
6079+
// RequiredDuringSchedulingRequiredDuringExecution is implemented
6080+
// RequiredDuringSchedulingRequiredDuringExecution: &core.NodeSelector{
6081+
// NodeSelectorTerms: []core.NodeSelectorTerm{
6082+
// {
6083+
// MatchExpressions: []core.NodeSelectorRequirement{
6084+
// {
6085+
// Key: "key1",
6086+
// Operator: core.NodeSelectorOpExists
6087+
// },
6088+
// },
6089+
// },
6090+
// },
6091+
// },
6092+
&core.Affinity{
6093+
NodeAffinity: &core.NodeAffinity{
6094+
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
6095+
NodeSelectorTerms: []core.NodeSelectorTerm{
6096+
{
6097+
MatchExpressions: []core.NodeSelectorRequirement{},
6098+
},
6099+
},
6100+
},
6101+
PreferredDuringSchedulingIgnoredDuringExecution: []core.PreferredSchedulingTerm{
6102+
{
6103+
Weight: 10,
6104+
Preference: core.NodeSelectorTerm{
6105+
MatchExpressions: []core.NodeSelectorRequirement{},
6106+
},
6107+
},
6108+
},
6109+
},
6110+
},
6111+
),
6112+
},
60726113
{ // Serialized pod affinity in affinity requirements in annotations.
60736114
ObjectMeta: metav1.ObjectMeta{
60746115
Name: "123",
@@ -6517,26 +6558,6 @@ func TestValidatePod(t *testing.T) {
65176558
}),
65186559
},
65196560
},
6520-
"invalid requiredDuringSchedulingIgnoredDuringExecution node selector term, matchExpressions must have at least one node selector requirement": {
6521-
expectedError: "spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions",
6522-
spec: core.Pod{
6523-
ObjectMeta: metav1.ObjectMeta{
6524-
Name: "123",
6525-
Namespace: "ns",
6526-
},
6527-
Spec: validPodSpec(&core.Affinity{
6528-
NodeAffinity: &core.NodeAffinity{
6529-
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
6530-
NodeSelectorTerms: []core.NodeSelectorTerm{
6531-
{
6532-
MatchExpressions: []core.NodeSelectorRequirement{},
6533-
},
6534-
},
6535-
},
6536-
},
6537-
}),
6538-
},
6539-
},
65406561
"invalid weight in preferredDuringSchedulingIgnoredDuringExecution in pod affinity annotations, weight should be in range 1-100": {
65416562
expectedError: "must be in the range 1-100",
65426563
spec: core.Pod{

0 commit comments

Comments
 (0)