Skip to content

Validate labelSelector in topologySpreadConstraints#111802

Merged
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
maaoBit:fix-labelSelectorValidate-missing
Dec 13, 2022
Merged

Validate labelSelector in topologySpreadConstraints#111802
k8s-ci-robot merged 1 commit intokubernetes:masterfrom
maaoBit:fix-labelSelectorValidate-missing

Conversation

@maaoBit
Copy link
Copy Markdown
Contributor

@maaoBit maaoBit commented Aug 11, 2022

Signed-off-by: maao maao420691301@gmail.com

What type of PR is this?

/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #111791

Special notes for your reviewer:

Does this PR introduce a user-facing change?

LabelSelectors specified in topologySpreadConstraints are now validated to ensure that pod is scheduled as expected. Existing pods with invalid LabelSelectors can be updated, but new pods are required to specify valid LabelSelectors.

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


@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. 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 Aug 11, 2022
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Please note that we're already in Test Freeze for the release-1.25 branch. This means every merged PR will be automatically fast-forwarded via the periodic ci-fast-forward job to the release branch of the upcoming v1.25.0 release.

Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Thu Aug 11 07:32:13 UTC 2022.

@k8s-ci-robot k8s-ci-robot added 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. labels Aug 11, 2022
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@maaoBit: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

Instructions 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 11, 2022
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @maaoBit. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Aug 11, 2022
@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. 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 Aug 11, 2022
@alaypatel07
Copy link
Copy Markdown
Contributor

/cc

Comment thread pkg/apis/core/validation/validation.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need to consider what happens to existing persisted data that doesn't pass this validation

This means we need to only apply this stricter validation when validating a create request or an update request of an object that already passes the strict validation.

The pattern we use for this is:

  1. plumbing the PodValidationOptions struct down to this function
  2. add an AllowInvalidTopologySpreadConstraintLabelSelector bool field to that struct
  3. populate that field in GetValidationOptionsFromPodSpecAndMeta:
  • set it to false when creating a new pod
  • set it to true when updating a pod where the old pod has invalid topology spread constraint label selectors
  • set it to false otherwise
  1. Make this new validation line conditional on that boolean field
  2. Add unit tests:
  • validate a new pod (should not allow invalid selectors)
  • validate an updated pod where the old pod has invalid selectors (should allow the new pod to have an invalid selector)
  • validate an updated pod where the old pod has valid selectors (should not allow the new pod to have an invalid selector)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for review. PR has been updated. PTAL

@liggitt liggitt added the api-review Categorizes an issue or PR as actively needing an API review. label Aug 16, 2022
@liggitt liggitt self-assigned this Aug 16, 2022
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 17, 2022
Comment thread pkg/api/pod/util.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wonder if we need another test for invalid matchlables but with AllowInvalidTopologySpreadConstraintLabelSelector set to true to account for an update with invalid pod

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 18, 2022
@maaoBit
Copy link
Copy Markdown
Contributor Author

maaoBit commented Aug 18, 2022

@alaypatel07 Done

Copy link
Copy Markdown
Member

@alculquicondor alculquicondor left a comment

Choose a reason for hiding this comment

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

It looks generally good, but there is something else that we need to make sure:

When tightening validation, a Pod that used to work should continue to work. For this PR, this means that if a Pod had an invalid labelSelector, it should have failed to schedule.

Can you verify that this is the case?

Comment thread pkg/api/pod/util.go Outdated
Comment thread pkg/apis/core/validation/validation.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rename to metavalidation

Comment thread pkg/apis/core/validation/validation_test.go Outdated
@maaoBit
Copy link
Copy Markdown
Contributor Author

maaoBit commented Nov 18, 2022

/test pull-kubernetes-verify

Comment thread pkg/api/pod/util.go Outdated
Comment thread pkg/api/pod/util_test.go Outdated
@liggitt
Copy link
Copy Markdown
Member

liggitt commented Nov 23, 2022

this lgtm, just a couple comments

/milestone v1.27

@k8s-ci-robot k8s-ci-robot added this to the v1.27 milestone Nov 23, 2022
Copy link
Copy Markdown
Member

@alculquicondor alculquicondor left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm
/hold for optional nit

Comment thread pkg/api/pod/util_test.go Outdated
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 24, 2022
Signed-off-by: maao <maao420691301@gmail.com>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 28, 2022
@alculquicondor
Copy link
Copy Markdown
Member

/lgtm
/hold cancel

This needs a release note btw.

@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 Nov 28, 2022
@alculquicondor
Copy link
Copy Markdown
Member

/hold
for release note

@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 Nov 28, 2022
@liggitt
Copy link
Copy Markdown
Member

liggitt commented Nov 28, 2022

/approve

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor, liggitt, maaoBit

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

The pull request process is described here

Details 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. 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 Nov 28, 2022
@dims
Copy link
Copy Markdown
Member

dims commented Dec 12, 2022

If you still need this PR then please rebase, if not, please close the PR

@maaoBit
Copy link
Copy Markdown
Contributor Author

maaoBit commented Dec 13, 2022

release note has been added, remove hold label
/hold cancel
@dims this PR has been rebased.

@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 Dec 13, 2022
@dims
Copy link
Copy Markdown
Member

dims commented Dec 13, 2022

i can see it in the merge queue - https://prow.k8s.io/tide

@k8s-ci-robot k8s-ci-robot merged commit cb03415 into kubernetes:master Dec 13, 2022
@k8s-ci-robot k8s-ci-robot modified the milestones: v1.27, v1.26 Dec 13, 2022
@ameukam
Copy link
Copy Markdown
Member

ameukam commented Dec 13, 2022

/milestone v1.27

The milestone_applier plugin was not configured to add 1.27 milestone

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

Status: API review completed, 1.27

Development

Successfully merging this pull request may close these issues.

pod creations are missing validation on spec.topologySpreadConstraints[*].labelSelector

9 participants