Change the implementation design of matchLabelKeys in PodTopologySpread to be aligned with PodAffinity#129874
Conversation
|
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/cc @sanposhiho |
|
I have submitted #129900 and will restart this PR once it is merged. |
|
This PR isn't blocked by #129900, right? |
|
I mean, you can implement a unit test case with the previous behavior in this PR, and |
92a93ae to
16ef4ec
Compare
|
@sanposhiho @macsko |
|
/release-note-edit |
I've submitted PR. |
8dc05f8 to
a33269c
Compare
…ad to be aligned with PodAffinity
a33269c to
1d563f9
Compare
| switch { | ||
| case opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && opts.OldPodViolatesMatchLabelKeysValidation: | ||
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | ||
| case opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && !opts.OldPodViolatesMatchLabelKeysValidation: | ||
| allErrs = append(allErrs, ValidateMatchLabelKeysAndMismatchLabelKeys(subFldPath, constraint.MatchLabelKeys, nil, constraint.LabelSelector)...) | ||
| case !opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && opts.OldPodViolatesLegacyMatchLabelKeysValidation: | ||
| allErrs = append(allErrs, ValidateMatchLabelKeysAndMismatchLabelKeys(subFldPath, constraint.MatchLabelKeys, nil, constraint.LabelSelector)...) | ||
| case !opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && !opts.OldPodViolatesLegacyMatchLabelKeysValidation: | ||
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | ||
| default: | ||
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | ||
| } |
There was a problem hiding this comment.
For my future sanity it will help to add some comments. Please review carefully to see if I've gotten it correct.
| switch { | |
| case opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && opts.OldPodViolatesMatchLabelKeysValidation: | |
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | |
| case opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && !opts.OldPodViolatesMatchLabelKeysValidation: | |
| allErrs = append(allErrs, ValidateMatchLabelKeysAndMismatchLabelKeys(subFldPath, constraint.MatchLabelKeys, nil, constraint.LabelSelector)...) | |
| case !opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && opts.OldPodViolatesLegacyMatchLabelKeysValidation: | |
| allErrs = append(allErrs, ValidateMatchLabelKeysAndMismatchLabelKeys(subFldPath, constraint.MatchLabelKeys, nil, constraint.LabelSelector)...) | |
| case !opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && !opts.OldPodViolatesLegacyMatchLabelKeysValidation: | |
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | |
| default: | |
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | |
| } | |
| // legacyValidationFunction is ValidateMatchLabelKeysInTopologySpread | |
| // preferredValidationFunction is ValidateMatchLabelKeysAndMismatchLabelKeys | |
| // OldPodViolatesMatchLabelKeysValidation==true means ValidateMatchLabelKeysAndMismatchLabelKeys failed, which means preferredValidation failed | |
| // OldPodViolatesLegacyMatchLabelKeysValidation==true means ValidateMatchLabelKeysInTopologySpread failed | |
| switch { | |
| case opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && opts.OldPodViolatesMatchLabelKeysValidation: | |
| // this case means that we want to use preferred validation, but the old pod doesn't pass new validation, so it must continue using legacyValidationFunction. This is because we don't allow the fields to change. | |
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | |
| case opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && !opts.OldPodViolatesMatchLabelKeysValidation: | |
| // this case means we want to use the preferred validation and the old pod worked with new validation, so we will continue requiring new the preferred validation to pass. | |
| allErrs = append(allErrs, ValidateMatchLabelKeysAndMismatchLabelKeys(subFldPath, constraint.MatchLabelKeys, nil, constraint.LabelSelector)...) | |
| case !opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && opts.OldPodViolatesLegacyMatchLabelKeysValidation: | |
| // this is the case where we want legacy validation and the old pod does not pass legacy validation. In this case we use the preferred (new) validation instead so that updates to other fields can happen. This allows us to enable the featuregate, then disable the featuregate and still be able to update the pod. | |
| allErrs = append(allErrs, ValidateMatchLabelKeysAndMismatchLabelKeys(subFldPath, constraint.MatchLabelKeys, nil, constraint.LabelSelector)...) | |
| case !opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && !opts.OldPodViolatesLegacyMatchLabelKeysValidation: | |
| // this is the case where we want legacy validation and the old pod passes legacy validation. In this case we use legacy validation | |
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | |
| default: | |
| // if we fall through, then we use legacy validation because that's what we did prior to the new gate. | |
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | |
| } |
There was a problem hiding this comment.
Thank you for your suggestion!
I've addressed.
| }, | ||
|
|
||
| MatchLabelKeysInPodTopologySpreadSelectorMerge: { | ||
| {Version: version.MustParse("1.34"), Default: true, PreRelease: featuregate.Beta}, |
There was a problem hiding this comment.
Noting for the record that this is adjustment to a feature already in beta, so going directly to beta and enabled by default is acceptable. We are gating this so that if this adjustment causes negative consequences for a cluster, a cluster-admin can use the feature as it was before instead of being trapped.
|
/label tide/merge-method-squash |
|
LGTM label has been added. DetailsGit tree hash: 72c970d8209fa5e7a64f0a266162a6c570cf646d |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, mochizuki875, sanposhiho The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
sanposhiho
left a comment
There was a problem hiding this comment.
I intended to review the PR after kubernetes/enhancements#5205 is merged though. Anyway..
| allErrs = append(allErrs, err) | ||
| } | ||
| allErrs = append(allErrs, validateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) | ||
| // legacyValidationFunction is ValidateMatchLabelKeysInTopologySpread |
There was a problem hiding this comment.
Wondering, in the first place though, do we need to have a validation on the update path? because all the related fields are immutable, right? So, instead of having those complexity, can we just skip validation on the update path?
There was a problem hiding this comment.
Considering the comment , I assumed all paths, including update path, must be validated.
we need to validate with either old or new validation, so branches that don't end with validation are a problem and the code currently in the PR appears to have multiple ways to end up not validating at all.
@deads2k, do you have any comments on this?
There was a problem hiding this comment.
I don't get that. What's the point of having the validation for the update path when you don't allow the field to be updated in the first place.
There was a problem hiding this comment.
I didn't notice the immutability check. We do normally re-validate everything anyway, but if we enforce immutability I agree we could simplify.
There was a problem hiding this comment.
Thanks, so I'll review it and submit a PR.
| default: | ||
| // If we fall through, then we use the legacyValidationFunction because that's what we did prior to the featuregate(MatchLabelKeysInPodTopologySpreadSelectorMerge). | ||
| allErrs = append(allErrs, ValidateMatchLabelKeysInTopologySpread(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...) |
There was a problem hiding this comment.
Just like the else block right after this, it is to make it clear that validation is always be performed.
However, maybe it could have been combined with the case just above(case !opts.AllowMatchLabelKeysInPodTopologySpreadSelectorMerge && !opts.OldPodViolatesLegacyMatchLabelKeysValidation)...
There was a problem hiding this comment.
The following else can be reached when opts.AllowMatchLabelKeysInPodTopologySpread is false, which is fine.
But, this default shouldn't be reached (iiuc), and we should remove it or we should, at least, log errors, not just returning something. (I do prefer removing it.)
There was a problem hiding this comment.
As you say, the default block is indeed unreachable.
So I'll submit a PR which remove it.
…ad to be aligned with PodAffinity (kubernetes#129874) * Change the implementation design of matchLabelKeys in PodTopologySpread to be aligned with PodAffinity * fix1
What type of PR is this?
/kind feature
/sig scheduling
What this PR does / why we need it:
As described in #129480, the design of
matchLabelKeysis different betweenpodAffinityandtopologySpreadConstraint, which might confuse users.This PR makes topologySpread's
matchLabelKeysbehave the same as podAffinity.Which issue(s) this PR fixes:
Fixes #129480
Special notes for your reviewer:
I plan to include a description in the documentation stating updating the labels is not supported.
kubernetes/website#49602kubernetes/website#49607
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: