AWS: fix int32 overflow computing memory from InstanceRequirements - #10171
AWS: fix int32 overflow computing memory from InstanceRequirements#10171pujitha24 wants to merge 1 commit into
Conversation
Motivation:
For an ASG using attribute-based InstanceRequirements (MixedInstancesPolicy,
no instance type overrides), updateCapacityWithRequirementsOverrides computed
the synthetic template node's memory capacity as:
int64(*instanceRequirements.MemoryMiB.Min*1024*1024)
Since the AWS SDK v2 migration, MemoryMiB.Min is *int32 (previously *int64 in
SDK v1). The int64() cast wraps the whole product, so the multiplication by
1024*1024 is evaluated in int32 before the cast is applied. For any Min of
2048 MiB (2 GiB) or greater this overflows int32 and wraps, e.g. 8192 MiB
wraps to 0. The resulting template node then advertises ~0 memory capacity,
every pending pod fails the NodeResourcesFit predicate with "Insufficient
memory", and the node group never scales up from zero.
Approach:
Move the int64() cast to the Min operand so the multiplication happens in
int64, matching the existing pattern used for other fields (e.g. AWS SDK v1
behavior before the migration).
Also updates the existing TestBuildNodeFromTemplate unit test, which
exercised this code path with MemoryMiB.Min = 4 - too small to trigger the
overflow, so it did not catch the regression. The test now uses Min = 8192,
which reproduces the exact wraparound described above.
Validation:
- With only the test change applied (fix reverted), the updated test fails:
`go test ./cloudprovider/aws/... -run 'TestBuildNodeFromTemplate$' -v`
reports "expected: 8589934592, actual: 0", reproducing the overflow.
- With the fix applied, `go test -race ./cloudprovider/aws/... -vet=all`
(mirroring this repo's `make test-ci` invocation) passes.
- `gofmt -s -l` on both changed files reports no issues.
- This change is scoped to cloudprovider/aws; no other field in this file
multiplies a *int32 SDK value by a constant before casting to int64.
Report: kubernetes#10167
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Assisted-by: claude-sonnet-5 (via Claude Code)
|
This issue is currently awaiting triage. If SIG Autoscaling contributors determines this is a relevant issue, they will accept it by applying the The DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Hi @pujitha24. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pujitha24 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe AWS provider now converts the minimum ChangesAWS memory capacity calculation
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to This localized fix prevents incorrect memory capacity calculations for AWS instance requirements and adds a regression test for the overflow case; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Verified this locally against
|
What type of PR is this?
/kind bug
What this PR does / why we need it:
For an ASG that uses attribute-based
InstanceRequirements(MixedInstancesPolicy, noexplicit instance-type overrides),
updateCapacityWithRequirementsOverridesincloudprovider/aws/aws_manager.gocomputed the synthetic template node's memorycapacity as
int64(*instanceRequirements.MemoryMiB.Min*1024*1024).Since the AWS SDK v2 migration,
MemoryMiB.Minis*int32(it was*int64in SDKv1). The
int64()cast wraps the whole product, so*Min * 1024 * 1024is evaluatedin
int32before the cast is applied. For anyMinof 2048 MiB (2 GiB) or more thisoverflows
int32and wraps — e.g. 8192 MiB wraps to 0. The template node thenadvertises ~0 memory capacity, every pending pod fails the
NodeResourcesFitpredicate with "Insufficient memory", and the node group never scales up from zero.
This PR moves the
int64()cast to theMinoperand so the multiplication happensin
int64, matching the pre-SDK-v2-migration behavior.It also updates the existing
TestBuildNodeFromTemplateunit test, which exercisedthis code path with
MemoryMiB.Min = 4— too small to trigger the overflow, so itdid not catch the regression. The test now uses
Min = 8192, which reproduces theexact wraparound.
Which issue(s) this PR fixes:
Fixes #10167
Special notes for your reviewer:
Validation performed locally (no live cluster available in this environment):
go test ./cloudprovider/aws/... -run 'TestBuildNodeFromTemplate$' -vreportsexpected: 8589934592, actual: 0, reproducing the exact overflow described in theissue.
go test -race ./cloudprovider/aws/... -vet=all(mirroringthis repo's
make test-ciinvocation) passes.gofmt -s -lon both changed files reports no issues.int64(X * const * const)cast-after-multiply patternelsewhere in
aws_manager.go:VCpuCount.MinandAcceleratorCount.Minare castdirectly with no multiplication (no overflow risk), and the other in-file use of
*1024*1024operates onMemoryMb, which is alreadyint64. No other instance ofthis bug exists in this file.
masterCI is currently green (checked viagh run list --branch master).Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
Summary by CodeRabbit