Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect PodTopologySpread after rolling upgrades #111441

Merged
merged 3 commits into from Jul 30, 2022

Conversation

denkensk
Copy link
Member

@denkensk denkensk commented Jul 26, 2022

What type of PR is this?

/kind feature
/kind api-change

What this PR does / why we need it:

PodTopologySpread is widely used in production environments, especially in service type workloads which employ Deployments. However, currently it has a limitation that manifests during rolling updates which causes the deployment to end up out of balance (98215, 105661,k8s-pod-topology spread is not respected after rollout).

The root cause is that PodTopologySpread constraints allow defining a key-value label selector, which applies to all pods in a Deployment irrespective of their owning ReplicaSet. As a result, when a new revision is rolled out, spreading will apply across pods from both the old and new ReplicaSets, and so by the time the new ReplicaSet is completely rolled out and the old one is rolled back, the actual spreading we are left with may not match expectations because the deleted pods from the older ReplicaSet will cause skewed distribution for the remaining pods.

Which issue(s) this PR fixes:

Fixes #98215
Fixes #105661

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Respect PodTopologySpread after rolling upgrades

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 26, 2022
@denkensk
Copy link
Member Author

/sig scheduling

@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. area/code-generation area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 26, 2022
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 26, 2022
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 26, 2022
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 26, 2022
@denkensk
Copy link
Member Author

/assign @ahg-g

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 28, 2022
@liggitt liggitt moved this from Assigned to In progress in API Reviews Jul 28, 2022
@liggitt liggitt moved this from In progress to Changes requested in API Reviews Jul 28, 2022
pkg/api/pod/util_test.go Outdated Show resolved Hide resolved
pkg/api/pod/util.go Outdated Show resolved Hide resolved
pkg/api/pod/util_test.go Outdated Show resolved Hide resolved
pkg/api/pod/util_test.go Outdated Show resolved Hide resolved
pkg/apis/core/validation/validation_test.go Outdated Show resolved Hide resolved
MatchLabelKeys: []string{"/simple"},
},
},
wantFieldErrors: []*field.Error{field.Invalid(fieldPathMatchLabelKeys, "/simple", "prefix part must be non-empty")},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix part must be non-empty this error msg is hard to understand at the first glance until I checked the source which split the string by '/'.

you may want to add another test string, such as an empty string, I am fine with this as is though.

pkg/features/kube_features.go Outdated Show resolved Hide resolved
@ahg-g
Copy link
Member

ahg-g commented Jul 29, 2022

looks good to me

@liggitt this is ready.

@liggitt liggitt moved this from Changes requested to Assigned in API Reviews Jul 29, 2022
@liggitt liggitt moved this from Assigned to In progress in API Reviews Jul 29, 2022
Copy link
Member

@liggitt liggitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API bits look good, just a few doc/lint/message nits

I didn't review the pkg/scheduler and test changes, will defer to scheduling reviewers/approvers for those changes

api/api-rules/violation_exceptions.list Outdated Show resolved Hide resolved
pkg/apis/core/types.go Outdated Show resolved Hide resolved
@@ -6490,6 +6490,7 @@ func validateTopologySpreadConstraints(constraints []core.TopologySpreadConstrai
if err := validateNodeInclusionPolicy(subFldPath.Child("nodeTaintsPolicy"), constraint.NodeTaintsPolicy); err != nil {
allErrs = append(allErrs, err)
}
allErrs = append(allErrs, validateMatchLabelKeys(subFldPath.Child("matchLabelKeys"), constraint.MatchLabelKeys, constraint.LabelSelector)...)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-existing, but I noticed validateTopologySpreadConstraints doesn't seem to validate constraint.LabelSelector at all... @ahg-g, can you open a separate issue to track that (need to make sure the scheduler is robust against completely invalid selectors, and consider how to fix this validation in the least disruptive way possible)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some update on this comments, the validation is actually done when the labels.Selector is built. e.g.

selector, err := metav1.LabelSelectorAsSelector(c.LabelSelector)

And it is validated here,

for i := range vals {
if err := validateLabelValue(key, vals[i], valuePath.Index(i)); err != nil {
allErrs = append(allErrs, err)
}

I think the original comment is still valid and the the validation mentioned above would mitigate the problem as the invalid label value won't be accepted at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that happens at time of use, not time of API write, which is not ideal (since the user has no idea the object they created is not working like they want it to)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pr sent: #112121

pkg/apis/core/validation/validation.go Outdated Show resolved Hide resolved
pkg/apis/core/validation/validation.go Outdated Show resolved Hide resolved
pkg/apis/core/validation/validation.go Outdated Show resolved Hide resolved
@liggitt liggitt moved this from In progress to Changes requested in API Reviews Jul 29, 2022
@ahg-g
Copy link
Member

ahg-g commented Jul 29, 2022

/milestone v1.25

@k8s-ci-robot k8s-ci-robot added this to the v1.25 milestone Jul 29, 2022
@liggitt liggitt moved this from Changes requested to API review completed, 1.25 in API Reviews Jul 30, 2022
@liggitt
Copy link
Member

liggitt commented Jul 30, 2022

/approve
API change lgtm

/hold looks like commits need squashing
will let @ahg-g lgtm once that is done

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 30, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: denkensk, liggitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 30, 2022
Signed-off-by: Alex Wang <wangqingcan1990@gmail.com>
Signed-off-by: Alex Wang <wangqingcan1990@gmail.com>
Signed-off-by: Alex Wang <wangqingcan1990@gmail.com>
@ahg-g
Copy link
Member

ahg-g commented Jul 30, 2022

/lgtm
/hold cancel

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jul 30, 2022
@k8s-ci-robot k8s-ci-robot merged commit 3902a53 into kubernetes:master Jul 30, 2022
@denkensk denkensk deleted the respect-topology branch July 31, 2022 08:06
@sftim
Copy link
Contributor

sftim commented Aug 1, 2022

@denkensk, could we also link to the relevant docs?

See #111194 for an example of a detailed release note that includes a link to docs.

@fedebongio
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/code-generation area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.25
10 participants