From 04e33401fe93d83320414e87f30570cdc24586de Mon Sep 17 00:00:00 2001 From: Ismail Alidzhikov <9372594+ialidzhikov@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:32:26 +0200 Subject: [PATCH] Address review comment from adrianmoisey --- .../pkg/utils/vpa/capping.go | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/vertical-pod-autoscaler/pkg/utils/vpa/capping.go b/vertical-pod-autoscaler/pkg/utils/vpa/capping.go index 271c8f2d6154..f4881ab39d4f 100644 --- a/vertical-pod-autoscaler/pkg/utils/vpa/capping.go +++ b/vertical-pod-autoscaler/pkg/utils/vpa/capping.go @@ -194,33 +194,30 @@ func applyVPAPolicyForContainer(containerName string, process := func(recommendation apiv1.ResourceList) { for resourceName, recommended := range recommendation { + var maxAllowed apiv1.ResourceList // containerPolicy can be nil (user does not have to configure it). if containerPolicy != nil { cappedToMin, _ := maybeCapToPolicyMin(recommended, resourceName, containerPolicy) recommendation[resourceName] = cappedToMin - maxAllowed := containerPolicy.MaxAllowed - if globalMaxAllowed != nil { - if maxAllowed == nil { - maxAllowed = globalMaxAllowed - } else { - // Set resources from the global maxAllowed if the VPA maxAllowed is missing them. - for resourceName, quantity := range globalMaxAllowed { - if _, ok := maxAllowed[resourceName]; !ok { - maxAllowed[resourceName] = quantity - } + maxAllowed = containerPolicy.MaxAllowed + } + + if globalMaxAllowed != nil { + if maxAllowed == nil { + maxAllowed = globalMaxAllowed + } else { + // Set resources from the global maxAllowed if the VPA maxAllowed is missing them. + for resourceName, quantity := range globalMaxAllowed { + if _, ok := maxAllowed[resourceName]; !ok { + maxAllowed[resourceName] = quantity } } } - - cappedToMax, _ := maybeCapToMax(cappedToMin, resourceName, maxAllowed) - recommendation[resourceName] = cappedToMax - } else { - if globalMaxAllowed != nil { - cappedToMax, _ := maybeCapToMax(recommended, resourceName, globalMaxAllowed) - recommendation[resourceName] = cappedToMax - } } + + cappedToMax, _ := maybeCapToMax(recommendation[resourceName], resourceName, maxAllowed) + recommendation[resourceName] = cappedToMax } }