Skip to content

Commit

Permalink
Address review comment from adrianmoisey
Browse files Browse the repository at this point in the history
  • Loading branch information
ialidzhikov committed Dec 13, 2024
1 parent 7e427ae commit 12f42ee
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions vertical-pod-autoscaler/pkg/utils/vpa/capping.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,33 +186,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
}
}

Expand Down

0 comments on commit 12f42ee

Please sign in to comment.