From 974053e0254e5065569bd3db1fab430fa62bbbbb Mon Sep 17 00:00:00 2001 From: Nuckal777 Date: Tue, 19 Sep 2023 11:17:01 +0200 Subject: [PATCH] Scale only cpu via millis --- internal/controllers/vpa_runnable.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/controllers/vpa_runnable.go b/internal/controllers/vpa_runnable.go index 053a6b1..0443981 100644 --- a/internal/controllers/vpa_runnable.go +++ b/internal/controllers/vpa_runnable.go @@ -73,7 +73,7 @@ func (v *VpaRunnable) reconcile(ctx context.Context) { largest := maxByMemory(viable) containers := int64(len(target.PodSpec.Containers)) // distribute a fraction of maximum capacity evenly across containers - cpuScaled := scaleQuantity(largest.Status.Allocatable.Cpu(), v.CapacityPercent/containers) + cpuScaled := scaleQuantityMilli(largest.Status.Allocatable.Cpu(), v.CapacityPercent/containers) memScaled := scaleQuantity(largest.Status.Allocatable.Memory(), v.CapacityPercent/containers) err = v.patchMaxRessources(ctx, patchParams{ vpa: target.Vpa, @@ -167,6 +167,10 @@ func maxByMemory(nodes []corev1.Node) corev1.Node { return maxNode } -func scaleQuantity(q *resource.Quantity, percent int64) *resource.Quantity { +func scaleQuantityMilli(q *resource.Quantity, percent int64) *resource.Quantity { return resource.NewMilliQuantity(q.MilliValue()*percent/scaleDivisor, q.Format) } + +func scaleQuantity(q *resource.Quantity, percent int64) *resource.Quantity { + return resource.NewQuantity(q.Value()*percent/scaleDivisor, q.Format) +}