Fix scaleQuantityProportionallyCPU function #8946
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 541 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.377
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8946"
general
weight: 0.35
iamzili
What type of PR is this?
/kind bug
/area vertical-pod-autoscaler
What this PR does / why we need it:
The current implementation of scaleQuantityProportionallyCPU is broken (possibly the
scaleQuantityProportionallyMemis broken as well, but I want to fix it in an another PR).When a
LimitRangeobject with type Pod exists in the namespace, and the algorithm proportionally increases or decreases recommendations, the division may produce an implicit issue. When remainders occur, the sum of the new recommendations does not satisfy the constraints defined in theLimitRange. For example (only the cpu is controlled):LimitRangeof type Pod definesmin.cpuas150m.-
c1:15m-
c2:100mscaleQuantityProportionallyCPU(15m, 115m, 150m, noRounding)returns 19m- formula used: (15150)/115
scaleQuantityProportionallyCPU(100m, 115m, 150m, noRounding)returns 130m.- formula used: (100150)/115
The sum of new recommendations is below 150m > (19m + 130m), which means that the pod is not going to be scheduled.
The issue with
scaleQuantityProportionallyCPUis that when the division executes, the implementation ignores any remainder.Special notes for your reviewer:
This PR refactors scaleQuantityProportionallyCPU so that, based on the rounding parameter (roundUpToFullUnit or roundDownToFullUnit), when a remainder occurs, the new algorithm adds one millicore to the quotient (whole number result of the division) per container when roundUpToFullUnit is used.
Previously, the function behaved as follows:
1. With
noRounding, if the formula produces1234567890m, the function returns1234567890m.2. With
roundUpToFullUnit, if the formula produces1234567890m, the function returns1234568.3. With
roundDownToFullUnit, if the formula produces1234567890m, the function returns1234567.Also the diffs in
vertical-pod-autoscaler/pkg/utils/vpa/capping_test.goare somewhat confusing. I removed one duplicated unit test from the file and added a completely new test.Does this PR introduce a user-facing change?
Yes, but the change is subtle and may not impact users at all. With the new implementation of
scaleQuantityProportionallyCPU, if the division produces a remainder, the function add 1 m to the quotient, or keep it as is. Using the example specified earlier:the sum of new recommendations ends up
1mhigher (i.e. 151m) than themin.cpudefined in theLimitRange. So from 19m we get 20m, from the 130 we get 131m which results in 151m. So technically we waste 1m but, that shouldn't be a problem. Even the resource.Quantity documentation states that 0.1m rounds up to 1m.When a Pod LimitRange object is in place with a
maxfield and we need to cap some recommendations, we lose some millicores, when the division produces a remainder . As a result, the per-container guaranteed or maximum allowed CPU millicore becomes 1m lower.``
release-note
``Fixed a bug where the presence of a LimitRange object with CPU constraints in the cluster prevented VPA from recreating Pods managed by the targeted controllers. The updated code section, which proportionally reduces resource requests and limits, could result in the loss of sub-millicore values.