Repository navigation
fix(aws): verify the offering the EC2 RI purchase path picks - #469
Conversation
|
Warning Review limit reached
This review includes 6 billable files and costs up to $1.50.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 2 minutes for your next included review. View limit details
Comment |
|
@coderabbitai review |
|
Independent adversarial review: CLEAN at
|
|
CI is green on head |
scanEC2OfferingPage checked only zone and offering type, so a wrong-tenancy, wrong-class, wrong-duration or wrong-product offering that AWS returned was bought. It now runs every offering through offeringMismatch via ec2OfferingQuery.want(), the same rule the exchange lookups use, and the not-found and pagination-cap errors carry the skip counts. The request already filters these fields, so this is defense-in-depth. Class, tenancy and duration stay strict when unset; live AWS population of those offering fields is unverified. Closes #457 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56c8786 to
f194876
Compare
|
Rebased onto
The commit is identical, so the CLEAN verdict for |
|
Merged by squash at reviewed head
CR waived: quota, adversarial review + local verification + green CI. Live-AWS gap noted in the verdict. Retrospective CodeRabbit review to run when quota returns. |
Summary
#451, #455 and #456 made the EC2 RI exchange lookups check every offering AWS returns against the request, using
offeringMismatchinproviders/aws/services/ec2/offering_match.go. The purchase path did not.scanEC2OfferingPageandfindOfferingchecked only the zone and the payment option of the offering they picked.PurchaseCommitment,ValidateOfferingandGetOfferingDetailsall usefindOffering.This PR applies the same rule to the purchase path.
ec2OfferingQuery.want()maps the purchase query (instance type, product, tenancy, scope, duration, offering class, payment option, AZ) ontoofferingWant.scanEC2OfferingPagenow callsofferingMismatch(o, q.want()), which uses the tiered rule:findOfferingappends per-reason skip counts to its not-found and page-cap errors, e.g. "3 offerings skipped: class=2, tenancy=1". The existing error text is kept.describeInputFromQuery) is unchanged. It already sends tenancy, class, duration, product, instance type, payment option and AZ as typed fields, so this is a second line of defence against an offering AWS returns that does not match. A test now pins that request shape.Effect: a wrong-tenancy, wrong-class, wrong-duration or wrong-product offering is skipped instead of purchased. If no offering matches, the purchase fails loud with the skip counts.
Live gap: this has not been checked against live AWS, i.e. that it always returns
OfferingClass,InstanceTenancyandDurationon offerings. If AWS omitted one, purchases would fail loud with "class=N" in the error rather than buy the wrong thing. No AWS call was made; this repo does not run cloud-backed checks unless they are explicitly intended. The exchange lookups already depend on the same fields.ValidateOfferingandGetOfferingDetailskeep their documented convertible default. Their only change is that a mismatched offering now errors.Closes #457 (follow-up to #233; refs #305).
Verification (macOS, Go 1.26.9)
(cd providers/aws && GOWORK=off go test -race -short ./...)passes.make build,make vetpass. golangci-lint v2.10.1 (the CI pin) reports 0 issues. gofmt is clean.purchase_offering_match_test.go:TestPurchaseCommitment_WrongOfferingIsNotPurchased: tenancy, class, duration and product subtests throughPurchaseCommitmentwith a mock that returns only the wrong offering. Each asserts the error andAssertNotCalledonPurchaseReservedInstancesOffering.TestFindOffering_SkipsWrongTenancyThenPicksMatch.TestFindOffering_NotFoundReportsSkipsandTestFindOffering_PaginationCapReportsSkips.TestFindOffering_VPCSuffixedProductStillMatches.TestScanEC2OfferingPage_CountsSkipsByReason.TestEC2OfferingQueryWant, against independent literals.TestDescribeInputFromQuery_SendsTenancyClassDurationProduct.OfferingClass: convertible, with no assertion edited.TestFindOffering_WrongVariantRejectednow also assertsoffering-type=1. The duration-vs-term price test gained anidOnlycolumn, becausefindOfferingnow rejects that offering first and the price guard inofferingprice.Pricestays reachable through the by-id re-describe.client.go, the four purchase subtests fail, as do the skip-count error tests,SkipsWrongTenancyThenPicksMatchandWrongVariantRejected.56c8786.Fakes only; no AWS call or purchase.
🤖 Generated with Claude Code