Skip to content

cleanup: use helper for update modes in recommender tests - #9976

Merged
kubernetes-prow[bot] merged 3 commits into
kubernetes:masterfrom
tanayarun:vpa/use-update-modes-helper
Jul 13, 2026
Merged

kubernetes-prow[bot] merged 3 commits into
kubernetes:masterfrom
tanayarun:vpa/use-update-modes-helper

Conversation

@tanayarun

@tanayarun tanayarun commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Both TestObjectCounter and TestObjectCounterResetsAllUpdateModes in recommender_test.go hardcoded the list of VPA update modes, so they silently missed InPlace and would miss any future mode as well.

This PR adds a shared sortedUpdateModes() helper (derived from vpa_types.GetUpdateModes()) and uses it in both tests, keeping test coverage in sync with the supported API update modes and eliminating the need to manually update multiple test cases whenever a new mode is added.

Which issue(s) this PR fixes:

Fixes #9971

Special notes for your reviewer:

Verified that all update modes returned by GetUpdateModes(), including InPlace, are covered by both tests.

Does this PR introduce a user-facing change?

NONE

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

@kubernetes-prow kubernetes-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Jul 13, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If SIG Autoscaling contributors 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-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jul 13, 2026
@kubernetes-prow
kubernetes-prow Bot requested a review from maxcao13 July 13, 2026 13:06
@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 13, 2026
@kubernetes-prow
kubernetes-prow Bot requested a review from omerap12 July 13, 2026 13:06
@kubernetes-prow kubernetes-prow Bot added do-not-merge/needs-area Indicates that a PR should not merge because it lacks an area label. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. area/vertical-pod-autoscaler Issues or PRs related to the Vertical Pod Autoscaler component labels Jul 13, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

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

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @tanayarun!

It looks like this is your first PR to kubernetes/autoscaler 🎉. 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/autoscaler 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. 😃

@kubernetes-prow kubernetes-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/needs-area Indicates that a PR should not merge because it lacks an area label. labels Jul 13, 2026

@omerap12 omerap12 left a comment

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.

Thanks for opening this. There are some issues that need to be addressed.

}

for _, mode := range sortedUpdateModes() {
mode := mode

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.

Why do we need this?

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.

My bad, removed. The extra copy was not needed here.

// vpa_types.GetUpdateModes helper, in a deterministic order. Sourcing the
// modes from the helper (instead of a hardcoded list) ensures these tests
// automatically pick up any new UpdateMode added to the API.
func sortedUpdateModes() []vpa_types.UpdateMode {

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.

Why do we need to sort the update modes?

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.

GetUpdateModes() returns a map, so iteration order is non deterministic. I added sorting to keep the generated subtest order stable across runs and make test output deterministic.

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.

I don't think that's necessary. having this should suffice:

diff --git a/vertical-pod-autoscaler/pkg/utils/metrics/recommender/recommender_test.go b/vertical-pod-autoscaler/pkg/utils/metrics/recommender/recommender_test.go
index 8cc00e2d2..fe59ec1c3 100644
--- a/vertical-pod-autoscaler/pkg/utils/metrics/recommender/recommender_test.go
+++ b/vertical-pod-autoscaler/pkg/utils/metrics/recommender/recommender_test.go
@@ -317,7 +317,7 @@ func labelsToKey(labels []*dto.LabelPair) string {
 }
 
 func TestObjectCounterResetsAllUpdateModes(t *testing.T) {
-	for _, mode := range sortedUpdateModes() {
+	for mode := range vpa_types.GetUpdateModes() {
 		t.Run(string(mode), func(t *testing.T) {
 			t.Cleanup(func() {
 				vpaObjectCount.Reset()

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.

gotcha, I've removed the helper and now iterate directly over GetUpdateModes().

@kubernetes-prow kubernetes-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 13, 2026

@omerap12 omerap12 left a comment

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.

Thanks!
/ok-to-test
/lgtm
/assign @adrianmoisey

@kubernetes-prow kubernetes-prow Bot 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 Jul 13, 2026
@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 13, 2026
@adrianmoisey

Copy link
Copy Markdown
Member

/approve

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adrianmoisey, tanayarun

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

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 13, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit 486d71c into kubernetes:master Jul 13, 2026
19 checks passed
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. area/vertical-pod-autoscaler Issues or PRs related to the Vertical Pod Autoscaler component cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VPA: use helper function for getting all update modes

3 participants