mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
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. ```
This commit is contained in:
commit
084715a282
@ -3005,9 +3005,6 @@ func ValidateNodeSelectorRequirement(rq core.NodeSelectorRequirement, fldPath *f
|
|||||||
func ValidateNodeSelectorTerm(term core.NodeSelectorTerm, fldPath *field.Path) field.ErrorList {
|
func ValidateNodeSelectorTerm(term core.NodeSelectorTerm, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
|
|
||||||
if len(term.MatchExpressions) == 0 {
|
|
||||||
return append(allErrs, field.Required(fldPath.Child("matchExpressions"), "must have at least one node selector requirement"))
|
|
||||||
}
|
|
||||||
for j, req := range term.MatchExpressions {
|
for j, req := range term.MatchExpressions {
|
||||||
allErrs = append(allErrs, ValidateNodeSelectorRequirement(req, fldPath.Child("matchExpressions").Index(j))...)
|
allErrs = append(allErrs, ValidateNodeSelectorRequirement(req, fldPath.Child("matchExpressions").Index(j))...)
|
||||||
}
|
}
|
||||||
|
@ -6069,6 +6069,47 @@ func TestValidatePod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{ // Serialized node affinity requirements.
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "123",
|
||||||
|
Namespace: "ns",
|
||||||
|
},
|
||||||
|
Spec: validPodSpec(
|
||||||
|
// TODO: Uncomment and move this block and move inside NodeAffinity once
|
||||||
|
// RequiredDuringSchedulingRequiredDuringExecution is implemented
|
||||||
|
// RequiredDuringSchedulingRequiredDuringExecution: &core.NodeSelector{
|
||||||
|
// NodeSelectorTerms: []core.NodeSelectorTerm{
|
||||||
|
// {
|
||||||
|
// MatchExpressions: []core.NodeSelectorRequirement{
|
||||||
|
// {
|
||||||
|
// Key: "key1",
|
||||||
|
// Operator: core.NodeSelectorOpExists
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
&core.Affinity{
|
||||||
|
NodeAffinity: &core.NodeAffinity{
|
||||||
|
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
|
||||||
|
NodeSelectorTerms: []core.NodeSelectorTerm{
|
||||||
|
{
|
||||||
|
MatchExpressions: []core.NodeSelectorRequirement{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PreferredDuringSchedulingIgnoredDuringExecution: []core.PreferredSchedulingTerm{
|
||||||
|
{
|
||||||
|
Weight: 10,
|
||||||
|
Preference: core.NodeSelectorTerm{
|
||||||
|
MatchExpressions: []core.NodeSelectorRequirement{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
{ // Serialized pod affinity in affinity requirements in annotations.
|
{ // Serialized pod affinity in affinity requirements in annotations.
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "123",
|
Name: "123",
|
||||||
@ -6517,26 +6558,6 @@ func TestValidatePod(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"invalid requiredDuringSchedulingIgnoredDuringExecution node selector term, matchExpressions must have at least one node selector requirement": {
|
|
||||||
expectedError: "spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions",
|
|
||||||
spec: core.Pod{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "123",
|
|
||||||
Namespace: "ns",
|
|
||||||
},
|
|
||||||
Spec: validPodSpec(&core.Affinity{
|
|
||||||
NodeAffinity: &core.NodeAffinity{
|
|
||||||
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
|
|
||||||
NodeSelectorTerms: []core.NodeSelectorTerm{
|
|
||||||
{
|
|
||||||
MatchExpressions: []core.NodeSelectorRequirement{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"invalid weight in preferredDuringSchedulingIgnoredDuringExecution in pod affinity annotations, weight should be in range 1-100": {
|
"invalid weight in preferredDuringSchedulingIgnoredDuringExecution in pod affinity annotations, weight should be in range 1-100": {
|
||||||
expectedError: "must be in the range 1-100",
|
expectedError: "must be in the range 1-100",
|
||||||
spec: core.Pod{
|
spec: core.Pod{
|
||||||
|
Loading…
Reference in New Issue
Block a user