Skip to content

fix: improve the pod level request validation #132551

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chao-liang
Copy link

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

The pod level request should be larger than the aggregated container requests.

  • The fix is to skip those resources not supported at the pod level for better efficiency.
  • A minor unit test is also added.

Which issue(s) this PR is related to:

Fixes #132449

Special notes for your reviewer:

The issue was actually addressed by #130131

The fix here is an improvement for efficiency.

Does this PR introduce a user-facing change?

NONE


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


The pod level request should be larger than the aggregated container
requests. The fix is to skip those resources not supported at the pod
level for better efficiency.

A minor unit test is also added.
@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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-sigs/prow repository.

Copy link

linux-foundation-easycla bot commented Jun 26, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 26, 2025
@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 26, 2025
@k8s-ci-robot
Copy link
Contributor

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.

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-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

Welcome @chao-liang!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jun 26, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG Apps Jun 26, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @chao-liang. 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.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 26, 2025
@ndixita
Copy link
Contributor

ndixita commented Jun 26, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 26, 2025
@ndixita
Copy link
Contributor

ndixita commented Jun 26, 2025

/test all

@ndixita
Copy link
Contributor

ndixita commented Jun 26, 2025

/lgtm

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

LGTM label has been added.

Git tree hash: 344a843947b6c47666e270abf50a7023f07c06c2

@ndixita
Copy link
Contributor

ndixita commented Jun 26, 2025

/assign @deads2k

@ndixita
Copy link
Contributor

ndixita commented Jun 26, 2025

/test pull-kubernetes-node-kubelet-serial-containerd-alpha-features

@ndixita
Copy link
Contributor

ndixita commented Jun 26, 2025

/test pull-kubernetes-node-kubelet-serial-podresources

@deads2k
Copy link
Contributor

deads2k commented Jun 26, 2025

/hold

While I concede that the current behavior is unexpected, we cannot simply change this here because in a downgrade case, you end up in a state where a flow like this is possible

  1. create pod/A with v1.44 which contains this change and matches the test case.
  2. downgrade to v1.43.
  3. Attempt to update the pod (set an annotate or resize).
  4. Fail because v1.43 validation does not allow the container resources.

This could be ratcheted in via options. See how we create PodValidationOptions in the strategy by inspecting the state of the old object. In one release we could add tolerance for this state if it already exists and in a future release we could allow it during create. It will also require some tests at that level to ensure we get the downgrade case correct.

@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 Jun 26, 2025
@liggitt
Copy link
Member

liggitt commented Jun 26, 2025

since this validation is only exercised when the field is populated, and it is an alpha field which cannot be populated by default yet, I think this is still fair game to tighten without worrying about ratcheting (once it reaches beta+, I agree we'd have to ratchet validation)

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 26, 2025
@k8s-ci-robot k8s-ci-robot requested review from deads2k and ndixita June 26, 2025 21:32
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@ndixita
Copy link
Contributor

ndixita commented Jun 26, 2025

since this validation is only exercised when the field is populated, and it is an alpha field which cannot be populated by default yet, I think this is still fair game to tighten without worrying about ratcheting (once it reaches beta+, I agree we'd have to ratchet validation)

+1 Agree with this. I understand how this can affect downgrade scenario, but since it is an alpha feature/field ratcheting might not be needed.

@chao-liang
Copy link
Author

Thanks for reviewing. I've synced with dixita offline, and pushed another commit to align with the current way of limit check.
Whether the resource is supported at pod level is already done in a prior function call validatePodResourceRequirements. This function and change would only focus on comparing the request/limit values between pod and containers.

@ndixita
Copy link
Contributor

ndixita commented Jun 26, 2025

Thanks for reviewing. I've synced with dixita offline, and pushed another commit to align with the current way of limit check. Whether the resource is supported at pod level is already done in a prior function call validatePodResourceRequirements. This function and change would only focus on comparing the request/limit values between pod and containers.

Could you please squash both commits

@chao-liang
Copy link
Author

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jun 26, 2025
@ndixita ndixita moved this from Needs Triage to Needs Approval in SIG Apps Jun 26, 2025
@chao-liang
Copy link
Author

/retest

@deads2k
Copy link
Contributor

deads2k commented Jun 27, 2025

I missed the alpha status. I agree we don't need to worry about downgrade on alpha. Thanks for the update to cover the case where not all eligible resources are specified.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chao-liang, deads2k

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 Jun 27, 2025
@toVersus
Copy link
Contributor

/remove-kind cleanup
/kind bug
/lgtm

Since this is a user-facing change, I think it would be good to include a release note. Something like this:

Fixed an bug where, when using the Pod Level Resources feature, specifying resource requirements at the container level for a resource not supported at the pod level would cause the API server to implicitly interpret the pod-level value as 0, resulting in a validation error.

And also, as noted in the PR template, could you add a link to the KEP in the following section?

#### Which issue(s) this PR is related to:

Fixes #132449  
KEP: https://github.com/kubernetes/enhancements/issues/2837

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. and removed kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Jun 28, 2025
@k8s-ci-robot
Copy link
Contributor

@toVersus: changing LGTM is restricted to collaborators

In response to this:

/remove-kind cleanup
/kind bug
/lgtm

Since this is a user-facing change, I think it would be good to include a release note. Something like this:

Fixed an bug where, when using the Pod Level Resources feature, specifying resource requirements at the container level for a resource not supported at the pod level would cause the API server to implicitly interpret the pod-level value as 0, resulting in a validation error.

And also, as noted in the PR template, could you add a link to the KEP in the following section?

#### Which issue(s) this PR is related to:

Fixes #132449  
KEP: https://github.com/kubernetes/enhancements/issues/2837

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-sigs/prow repository.

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/bug Categorizes issue or PR as related to a bug. 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. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
Status: Needs Approval
Development

Successfully merging this pull request may close these issues.

[Pod Level Resources] Pod-level resource validation fails when container-level is set for other resource
6 participants