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

feat: forbid to set matchLabelKeys when labelSelector isn’t set in topologySpreadConstraints #116535

Merged
merged 3 commits into from
Mar 14, 2023

Conversation

denkensk
Copy link
Member

@denkensk denkensk commented Mar 13, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

When users set lableSelector in topologySpreadConstraints as "null", it represents labels.Nothing(), so the key in matchLabelKeys needs to be ignored.

     topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: kubernetes.io/hostname
          whenUnsatisfiable: DoNotSchedule
          matchLabelKeys:
            - app
            - pod-template-hash

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

It's ok to change the behavior because the feature is graduating to beta in 1.27

Does this PR introduce a user-facing change?

forbid to set matchLabelKeys when labelSelector isn’t set in topologySpreadConstraints

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


@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. 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. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 13, 2023
@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 13, 2023
@sanposhiho
Copy link
Member

@denkensk it's better to have a release note since this change may break someone's PodTopologySpread with MatchLabelKeys.

@sanposhiho
Copy link
Member

/triage accepted
/priority important-soon

(Probably, we want to merge this before code-freeze since the matchLabelKeys in TopologySpread is gonna be beta and get enabled by default in v1.27)

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed 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 Mar 13, 2023
@denkensk
Copy link
Member Author

/assign @alculquicondor

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Mar 13, 2023
@alculquicondor
Copy link
Member

Add in notes to reviewer:

It's ok to change the behavior because the feature is graduating to beta in 1.27

@denkensk
Copy link
Member Author

Add in notes to reviewer:

It's ok to change the behavior because the feature is graduating to beta in 1.27

Added

@alculquicondor
Copy link
Member

release note is out-of-date

/hold

@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 Mar 14, 2023
@alculquicondor
Copy link
Member

/lgtm cancel

Please also update the API field comment to state the validation rule

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 14, 2023
@liggitt liggitt self-assigned this Mar 14, 2023
@liggitt liggitt added this to the v1.27 milestone Mar 14, 2023
@k8s-ci-robot k8s-ci-robot added area/code-generation kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Mar 14, 2023
@denkensk denkensk changed the title fix: key in matchLabelKeys needs to be ignored when LabelSelector is nil feat: forbid to set matchLabelKeys when labelSelector isn’t set in topologySpreadConstraints Mar 14, 2023
@denkensk
Copy link
Member Author

/lgtm cancel

Please also update the API field comment to state the validation rule

Updated. @alculquicondor

@@ -5972,8 +5972,12 @@ type TopologySpreadConstraint struct {
// spreading will be calculated. The keys are used to lookup values from the
// incoming pod labels, those key-value labels are ANDed with labelSelector
// to select the group of existing pods over which spreading will be calculated
// for the incoming pod. Keys that don't exist in the incoming pod labels will
// for the incoming pod. The same key is forbidden to exist in both MatchLabelKeys and LabelSelector.
// MatchLabelKeys is forbidden to set when LabelSelector isn't set.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// MatchLabelKeys is forbidden to set when LabelSelector isn't set.
// MatchLabelKeys cannot be set when LabelSelector isn't set.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: Alex Wang <wangqingcan1990@gmail.com>
@alculquicondor
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 14, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: ec0d545c81ea1c762568452afdf4507f8cbf8168

@alculquicondor
Copy link
Member

This is a bug fix, so it qualifies to be merged before test freeze.

@liggitt
Copy link
Member

liggitt commented Mar 14, 2023

/approve
API doc and validation change lgtm (this field was alpha in 1.26, tightening validation before releasing as beta is in bounds)

@alculquicondor has lgtm and can cancel hold

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor, 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 Mar 14, 2023
@alculquicondor
Copy link
Member

FYI: The website needs updates. The example doesn't have a node-selector https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/#spread-constraint-definition

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 14, 2023
@k8s-ci-robot k8s-ci-robot merged commit f2e1a67 into kubernetes:master Mar 14, 2023
@denkensk denkensk deleted the fix-match branch March 15, 2023 02:38
@denkensk
Copy link
Member Author

FYI: The website needs updates. The example doesn't have a node-selector https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/#spread-constraint-definition

/hold cancel

Update it in kubernetes/website#40008

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/code-generation 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/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. 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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.27
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants