From 9a57ecd597858c538e2bb8b5465195bb935d969b Mon Sep 17 00:00:00 2001 From: nikimanoledaki Date: Wed, 29 May 2024 10:13:35 +0200 Subject: [PATCH] Change mem value to kilobyte --- .../pkg/updater/priority/update_priority_calculator.go | 5 +++-- .../pkg/updater/priority/update_priority_calculator_test.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator.go b/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator.go index f7e3729a9bb8..d47a4ae9f516 100644 --- a/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator.go +++ b/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator.go @@ -24,6 +24,7 @@ import ( "time" apiv1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/sets" vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1" "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/annotations" @@ -174,7 +175,7 @@ func (calc *UpdatePriorityCalculator) GetProcessedRecommendationTargets(r *vpa_t if cr.Target != nil { sb.WriteString("target: ") if !cr.Target.Memory().IsZero() { - sb.WriteString(fmt.Sprintf("%sK ", cr.Target.Memory().AsDec())) + sb.WriteString(fmt.Sprintf("%dk ", cr.Target.Memory().ScaledValue(resource.Kilo))) } if !cr.Target.Cpu().IsZero() { sb.WriteString(fmt.Sprintf("%vm; ", cr.Target.Cpu().MilliValue())) @@ -183,7 +184,7 @@ func (calc *UpdatePriorityCalculator) GetProcessedRecommendationTargets(r *vpa_t if cr.UncappedTarget != nil { sb.WriteString("uncappedTarget: ") if !cr.UncappedTarget.Memory().IsZero() { - sb.WriteString(fmt.Sprintf("%sK ", cr.UncappedTarget.Memory().AsDec())) + sb.WriteString(fmt.Sprintf("%dk ", cr.UncappedTarget.Memory().ScaledValue(resource.Kilo))) } if !cr.UncappedTarget.Cpu().IsZero() { sb.WriteString(fmt.Sprintf("%vm;", cr.UncappedTarget.Cpu().MilliValue())) diff --git a/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator_test.go b/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator_test.go index 4af15a5e7c4e..2d169d38afad 100644 --- a/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator_test.go +++ b/vertical-pod-autoscaler/pkg/updater/priority/update_priority_calculator_test.go @@ -565,7 +565,7 @@ func TestAddPodLogs(t *testing.T) { { name: "container with target and uncappedTarget", givenRec: test.Recommendation().WithContainer(containerName).WithTarget("4", "10M").Get(), - expectedLog: "container1: target: 10000000K 4000m; uncappedTarget: 10000000K 4000m;\n", + expectedLog: "container1: target: 10000k 4000m; uncappedTarget: 10000k 4000m;\n", }, { name: "container with cpu only", @@ -575,7 +575,7 @@ func TestAddPodLogs(t *testing.T) { { name: "container with memory only", givenRec: test.Recommendation().WithContainer(containerName).WithTarget("", "10M").Get(), - expectedLog: "container1: target: 10000000K uncappedTarget: 10000000K \n", + expectedLog: "container1: target: 10000k uncappedTarget: 10000k \n", }, } for _, tc := range testCases {