Skip to content

Commit 3314cf9

Browse files
committed
Address review comment from adrianmoisey
1 parent 47402af commit 3314cf9

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

vertical-pod-autoscaler/pkg/utils/vpa/capping.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,33 +195,30 @@ func applyVPAPolicyForContainer(containerName string,
195195

196196
process := func(recommendation apiv1.ResourceList) {
197197
for resourceName, recommended := range recommendation {
198+
var maxAllowed apiv1.ResourceList
198199
// containerPolicy can be nil (user does not have to configure it).
199200
if containerPolicy != nil {
200201
cappedToMin, _ := maybeCapToPolicyMin(recommended, resourceName, containerPolicy)
201202
recommendation[resourceName] = cappedToMin
202203

203-
maxAllowed := containerPolicy.MaxAllowed
204-
if globalMaxAllowed != nil {
205-
if maxAllowed == nil {
206-
maxAllowed = globalMaxAllowed
207-
} else {
208-
// Set resources from the global maxAllowed if the VPA maxAllowed is missing them.
209-
for resourceName, quantity := range globalMaxAllowed {
210-
if _, ok := maxAllowed[resourceName]; !ok {
211-
maxAllowed[resourceName] = quantity
212-
}
204+
maxAllowed = containerPolicy.MaxAllowed
205+
}
206+
207+
if globalMaxAllowed != nil {
208+
if maxAllowed == nil {
209+
maxAllowed = globalMaxAllowed
210+
} else {
211+
// Set resources from the global maxAllowed if the VPA maxAllowed is missing them.
212+
for resourceName, quantity := range globalMaxAllowed {
213+
if _, ok := maxAllowed[resourceName]; !ok {
214+
maxAllowed[resourceName] = quantity
213215
}
214216
}
215217
}
216-
217-
cappedToMax, _ := maybeCapToMax(cappedToMin, resourceName, maxAllowed)
218-
recommendation[resourceName] = cappedToMax
219-
} else {
220-
if globalMaxAllowed != nil {
221-
cappedToMax, _ := maybeCapToMax(recommended, resourceName, globalMaxAllowed)
222-
recommendation[resourceName] = cappedToMax
223-
}
224218
}
219+
220+
cappedToMax, _ := maybeCapToMax(recommendation[resourceName], resourceName, maxAllowed)
221+
recommendation[resourceName] = cappedToMax
225222
}
226223
}
227224

0 commit comments

Comments
 (0)