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

Ensure CPU and Memory values are properly backfilled in GetContainersResources when VPA only touches one of CPU or Memory #7037

Closed
wants to merge 13 commits into from

Conversation

raywainman
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

In the GetContainersResources function there is an addAll boolean which is used to ensure that when applying the VPA recommendations, all other resource usage information is still preserved in the final output.

For example, when only applying recommendations to a single container in a pod, this would ensure other containers are included in the output.

There is a bug in this code for VPAs that only touch CPU or Memory where it would drop the other resource value.

Which issue(s) this PR fixes:

No issue filed.

Special notes for your reviewer:

Does this PR introduce a user-facing change?

No - this code path (with addAll = true is not actually anywhere in this repository. Some Cloud Providers may be relying on this path internally.

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

None

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 12, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: raywainman
Once this PR has been reviewed and has the lgtm label, please assign voelzmo for approval. For more information see the Kubernetes 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

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
pod := test.Pod().WithName("pod").AddContainer(tc.container).Get()
resources := GetContainersResources(pod, tc.vpa.Spec.ResourcePolicy, *tc.vpa.Status.Recommendation, nil, true, vpa_api_util.ContainerToAnnotationsMap{})
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to also add some tests for when addAll is set to false?

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 initially kept them out because this scenario is implicitly tested with the GetContainersResourcesForPod testing that is done above this, however we probably shouldn't rely on this implementation detail incase it changes in the future.

Added some tests covering the addAll = false case. This is much simpler because it will only return the values that VPA changed.

Thanks!

@raywainman
Copy link
Contributor Author

I've made a mess of this PR, will open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants