Skip to content

[FG:InPlacePodVerticalScaling] Enable removing resource limits from containers #127143

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 3 commits into
base: master
Choose a base branch
from

Conversation

hshiina
Copy link
Contributor

@hshiina hshiina commented Sep 5, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR fixes handling cases where resources limits are max at InPlacePodVerticalScaling.

When one of containers in a pod has no limits for a resource, no limits will be configured in the cgroup of the pod. This fix allows resizing the resource in a container that has limits when another container in the pod does not have limits for the resource. In doPodResizeAction(), this fix allows a container to be resized even if the pod resources are unlimited (the values in the pod resource is nil).

This PR also enables removing resource limits from containers by following changes:

  • Update pod cgroup resources to max
  • Update container resources to max with CRI API UpdateContainerResource().
  • Display resource limits in container status while limits are being removed.

Which issue(s) this PR fixes:

Fixes #128675

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Enabled removing resource limits and requests at InPlacePodVerticalScaling.

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


@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. 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-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 5, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @hshiina. 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 the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Sep 5, 2024
@k8s-ci-robot k8s-ci-robot added area/kubelet area/test sig/node Categorizes an issue or PR as relevant to SIG Node. 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 Sep 5, 2024
@hshiina hshiina changed the title [InPlacePodVerticalScaling [WIP][InPlacePodVerticalScaling] Enable removing resource limits from containers Sep 5, 2024
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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 Sep 5, 2024
@hshiina
Copy link
Contributor Author

hshiina commented Sep 5, 2024

/kind feature

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. and removed do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Sep 5, 2024
@hshiina hshiina changed the title [WIP][InPlacePodVerticalScaling] Enable removing resource limits from containers [WIP][FG:InPlacePodVerticalScaling] Enable removing resource limits from containers Sep 5, 2024
@kannon92
Copy link
Contributor

/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 Sep 11, 2024
@hshiina
Copy link
Contributor Author

hshiina commented Sep 27, 2024

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

@tallclair
Copy link
Member

/assign

@k8s-ci-robot k8s-ci-robot modified the milestones: v1.33, v1.34 Mar 21, 2025
if cStatus.Resources.CPULimit.MilliValue() > cm.MinMilliCPULimit ||
resources.Limits.Cpu().MilliValue() > cm.MinMilliCPULimit {
resources.Limits[v1.ResourceCPU] = cStatus.Resources.CPULimit.DeepCopy()
if cStatus.Resources != nil && cStatus.Resources.CPULimit != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit / optional / preexisting (take it or leave it):

this code looks like you are doing (almost) the same thing 3 times in a row, once for cpu limits, then once for memory limits, then once for cpu requests... makes me feel like it can / should be put into a helper (though admittedly this may not be as straightforward as I am imagining in my head)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though we should do so, fixing and refactoring at the same time could make review difficult. So, I don't introduce a helper in this PR.

}
} else if resources.Requests != nil && !resources.Requests.Cpu().IsZero() {
// Only if requests is in the allocation, restore limits to container sutatus from old status.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Only if requests is in the allocation, restore limits to container sutatus from old status.
// Only if requests is in the allocation, restore limits to container status from old status.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed. Thanks!

Comment on lines 788 to 789
value := maxValue
podResources.Memory = &value
Copy link
Contributor

@natasha41575 natasha41575 Apr 30, 2025

Choose a reason for hiding this comment

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

nit

Suggested change
value := maxValue
podResources.Memory = &value
podResources.Memory = ptr.To(maxValue)

(import "k8s.io/utils/ptr")

same in other places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks.

return nil
}
if m.cpuCFSQuota && containerResources.Linux.CpuQuota == 0 {
containerResources.Linux.CpuQuota = -1
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this value -1 for the same reason that the maxValue const you added to pkg/kubelet/kuberuntime/kuberuntime_manager.go is -1?

If so, consider putting the maxValue const somewhere that it can be shared in both places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are slightly different. This -1 is passed to the runtime for updating a container resource while the other is passed to libcontainer/cgroups for updating pod cgroups. I added a few comments.

if podResources == nil {
klog.ErrorS(nil, "Unable to get resource configuration", "pod", pod.Name)
result.Fail(fmt.Errorf("unable to get resource configuration processing resize for pod %s", pod.Name))
return
}

const maxValue = int64(-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see in your comment #127143 (comment) that this doesn't appear to be documented anywhere, maybe it'll be helpful to leave a comment here with this context so that in the future we can remember where this constant came from

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment.

CPU string `json:"cpu,omitempty"`
Memory string `json:"memory,omitempty"`
EphStor string `json:"ephemeral-storage,omitempty"`
CPU *string `json:"cpu"`
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to allow null in a patch for removing requests and limits.

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 2, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hshiina
Once this PR has been reviewed and has the lgtm label, please assign smarterclayton for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link
Contributor Author

@hshiina hshiina left a comment

Choose a reason for hiding this comment

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

Thank you for your review.

if cStatus.Resources.CPULimit.MilliValue() > cm.MinMilliCPULimit ||
resources.Limits.Cpu().MilliValue() > cm.MinMilliCPULimit {
resources.Limits[v1.ResourceCPU] = cStatus.Resources.CPULimit.DeepCopy()
if cStatus.Resources != nil && cStatus.Resources.CPULimit != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though we should do so, fixing and refactoring at the same time could make review difficult. So, I don't introduce a helper in this PR.

return nil
}
if m.cpuCFSQuota && containerResources.Linux.CpuQuota == 0 {
containerResources.Linux.CpuQuota = -1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are slightly different. This -1 is passed to the runtime for updating a container resource while the other is passed to libcontainer/cgroups for updating pod cgroups. I added a few comments.

if podResources == nil {
klog.ErrorS(nil, "Unable to get resource configuration", "pod", pod.Name)
result.Fail(fmt.Errorf("unable to get resource configuration processing resize for pod %s", pod.Name))
return
}

const maxValue = int64(-1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment.

Comment on lines 788 to 789
value := maxValue
podResources.Memory = &value
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks.


return false
}

Copy link
Member

Choose a reason for hiding this comment

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

this is changing a behavior in a graduated beta api, should you not first amend this change to the corresponding KEP instead of trying to get the change directly? or is this PR just asking for feedback?

Copy link
Member

Choose a reason for hiding this comment

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

oh, I See @tallclair already commented here #127143 (comment) ,

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 7, 2025
Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

/lgtm

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

LGTM label has been added.

Git tree hash: b9a73fb753a3b57d866fa5738a6c2e463833ffd2

@tallclair
Copy link
Member

@hshiina want to try and get this merged in v1.34?

@hshiina
Copy link
Contributor Author

hshiina commented May 19, 2025

@hshiina want to try and get this merged in v1.34?

Yes, I would like to complete this work if possible.

hshiina added 3 commits May 25, 2025 19:16
This fix enables removing resource limits and requests from containers
by following changes:
- Update pod cgroup resources to max
- Update container resources to max with CRI API
  UpdateContainerResource().
- Display resource limits in container status while limits are being
  removed.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 25, 2025
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 25, 2025
@k8s-ci-robot
Copy link
Contributor

@hshiina: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-unit-windows-master 5052f25 link false /test pull-kubernetes-unit-windows-master
pull-kubernetes-e2e-kind 5052f25 link true /test pull-kubernetes-e2e-kind
pull-kubernetes-e2e-gce 5052f25 link true /test pull-kubernetes-e2e-gce
pull-kubernetes-e2e-capz-windows-master 5052f25 link false /test pull-kubernetes-e2e-capz-windows-master

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@tico88612
Copy link
Member

Hello @hshiina @tallclair @natasha41575
This PR has not been updated for 1 month, so I'd like to check the status. If there's anything we can do, please let us know.
The code freeze is starting 02:00 UTC Friday 25th July 2025 (about 3 weeks from now). Please make sure the PR has both lgtm and approved labels before the code freeze. Thanks!

@tico88612 tico88612 moved this from Pending inclusion to Tracked in [sig-release] Bug Triage Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/kubelet area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. 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. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Needs Triage
Status: PRs Waiting on Author
Status: In Progress
Status: Tracked
Development

Successfully merging this pull request may close these issues.

[FG:InPlacePodVerticalScaling] Support removing requests and limits (from Burstable pods)