From a730b4450b5b68b3599f3680dd77253d5048685b Mon Sep 17 00:00:00 2001 From: Adrian Moisey Date: Sun, 26 Jan 2025 11:15:53 +0200 Subject: [PATCH 1/2] Add failing test for humanize bug Related to: https://github.com/kubernetes/autoscaler/issues/7770 --- .../pkg/recommender/model/types_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vertical-pod-autoscaler/pkg/recommender/model/types_test.go b/vertical-pod-autoscaler/pkg/recommender/model/types_test.go index adbceabcf51..c94b14772de 100644 --- a/vertical-pod-autoscaler/pkg/recommender/model/types_test.go +++ b/vertical-pod-autoscaler/pkg/recommender/model/types_test.go @@ -93,6 +93,18 @@ func TestResourcesAsResourceList(t *testing.T) { apiv1.ResourceMemory: *resource.NewQuantity(839500000, resource.DecimalSI), }, }, + { + name: "zero values without humanize", + resources: Resources{ + ResourceCPU: 1000, + ResourceMemory: 2852574758, // 2.66Gi + }, + humanize: true, + resourceList: apiv1.ResourceList{ + apiv1.ResourceCPU: *resource.NewMilliQuantity(1000, resource.DecimalSI), + apiv1.ResourceMemory: resource.MustParse("2.66Gi"), + }, + }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { From e20dda33b2cfeca958e9bd590c8f2e295d71e4a9 Mon Sep 17 00:00:00 2001 From: Adrian Moisey Date: Sun, 26 Jan 2025 12:12:24 +0200 Subject: [PATCH 2/2] This should pass --- vertical-pod-autoscaler/pkg/recommender/model/types_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vertical-pod-autoscaler/pkg/recommender/model/types_test.go b/vertical-pod-autoscaler/pkg/recommender/model/types_test.go index c94b14772de..224fb617fb8 100644 --- a/vertical-pod-autoscaler/pkg/recommender/model/types_test.go +++ b/vertical-pod-autoscaler/pkg/recommender/model/types_test.go @@ -32,6 +32,7 @@ type ResourcesAsResourceListTestCase struct { } func TestResourcesAsResourceList(t *testing.T) { + memory, _ := resource.ParseQuantity("2.66") testCases := []ResourcesAsResourceListTestCase{ { name: "basic resources without humanize", @@ -100,9 +101,10 @@ func TestResourcesAsResourceList(t *testing.T) { ResourceMemory: 2852574758, // 2.66Gi }, humanize: true, + resourceList: apiv1.ResourceList{ apiv1.ResourceCPU: *resource.NewMilliQuantity(1000, resource.DecimalSI), - apiv1.ResourceMemory: resource.MustParse("2.66Gi"), + apiv1.ResourceMemory: memory, }, }, }