feat(cr): pre-allocate PAYG VMs into CR reservation slots on cr creation/modification#951
feat(cr): pre-allocate PAYG VMs into CR reservation slots on cr creation/modification#951mblos wants to merge 4 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a PAYG (Pay-As-You-Go) pre-allocation phase to the committed-resource reservation manager. A new ChangesPAYG Pre-Allocation for Committed-Resource Reservation Slots
Sequence Diagram(s)sequenceDiagram
participant CommittedResourceController
participant ReservationManager
participant ScanAZForPaygCandidates
participant k8sClient
participant VMSource
CommittedResourceController->>ReservationManager: ApplyCommitmentState (VMSource propagated)
ReservationManager->>ReservationManager: Phase 1-4 (existing slot sync)
alt VMSource != nil and delta > 0 and AZ set
ReservationManager->>ScanAZForPaygCandidates: az, projectID, flavorGroup
ScanAZForPaygCandidates->>k8sClient: list Hypervisors by AZ label
ScanAZForPaygCandidates->>k8sClient: list CR reservations → buildAllocatedVMSet
ScanAZForPaygCandidates->>VMSource: GetVMs(projectID)
ScanAZForPaygCandidates-->>ReservationManager: map[hv][]PAYGCandidate
loop largest-first candidates while delta > 0
ReservationManager->>ReservationManager: newPaygReservation (TargetHost, CPU, Allocations)
ReservationManager->>k8sClient: create Reservation
end
else scan fails or VMSource nil
ReservationManager->>k8sClient: Phase 5 blind Reservation create
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
internal/scheduling/reservations/commitments/reservation_manager_test.go (1)
495-500: ⚡ Quick winAssert allocation resource maps in PAYG test cases.
Current PAYG assertions check allocation presence only. Add checks for
Allocations[vm].Resourceskeys (at least memory/cpu) so schema-shape regressions are caught in unit tests.Also applies to: 557-559
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/scheduling/reservations/commitments/reservation_manager_test.go` around lines 495 - 500, The current PAYG test assertions only check if the vmUUID key exists in the Allocations map and verify the ResourceName value, but do not validate the actual resource values (memory and CPU) within the Resources field of each allocation. Add assertions after the existing Allocations[vmUUID] presence check to verify that Allocations[vmUUID].Resources contains expected keys for memory and CPU with appropriate values. Apply this same pattern to the additional test cases referenced around lines 557-559 to ensure schema-shape regressions are caught during testing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@internal/scheduling/reservations/commitments/committed_resource_controller.go`:
- Around line 321-323: The `VMSource` field is being set on the
`ReservationManager` in the normal apply path (line 322 shows `mgr.VMSource =
r.VMSource`), but the rollback apply path creates a fresh `ReservationManager`
without propagating this field. Find where the rollback path instantiates a new
`ReservationManager` and apply the same field assignment pattern: after creating
the manager with `NewReservationManager(r.Client)`, also set `mgr.VMSource =
r.VMSource` to ensure consistent behavior between the normal and rollback apply
paths.
In `@internal/scheduling/reservations/commitments/reservation_manager.go`:
- Around line 535-538: In the newPaygReservation function where
CommittedResourceAllocation is initialized for candidate.VMID in the Allocations
map, add the required Resources field in addition to the existing
CreationTimestamp. The Resources field should be a map that specifies the
committed resources for the allocation to satisfy API validation requirements
for PAYG pre-allocations.
---
Nitpick comments:
In `@internal/scheduling/reservations/commitments/reservation_manager_test.go`:
- Around line 495-500: The current PAYG test assertions only check if the vmUUID
key exists in the Allocations map and verify the ResourceName value, but do not
validate the actual resource values (memory and CPU) within the Resources field
of each allocation. Add assertions after the existing Allocations[vmUUID]
presence check to verify that Allocations[vmUUID].Resources contains expected
keys for memory and CPU with appropriate values. Apply this same pattern to the
additional test cases referenced around lines 557-559 to ensure schema-shape
regressions are caught during testing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 368f8ffd-6d05-45f4-b6a0-562c42ff920c
📒 Files selected for processing (7)
cmd/manager/main.gointernal/scheduling/reservations/commitments/committed_resource_controller.gointernal/scheduling/reservations/commitments/integration_test.gointernal/scheduling/reservations/commitments/payg_candidates.gointernal/scheduling/reservations/commitments/payg_candidates_test.gointernal/scheduling/reservations/commitments/reservation_manager.gointernal/scheduling/reservations/commitments/reservation_manager_test.go
| Allocations: map[string]v1alpha1.CommittedResourceAllocation{ | ||
| candidate.VMID: { | ||
| CreationTimestamp: metav1.Now(), | ||
| }, |
There was a problem hiding this comment.
Populate required Allocations[*].Resources for PAYG pre-allocations.
At Line 537, newPaygReservation creates CommittedResourceAllocation entries with only CreationTimestamp. The allocation contract requires a Resources map, so this payload can be rejected by API validation and break PAYG slot creation.
Suggested fix
CommittedResourceReservation: &v1alpha1.CommittedResourceReservationSpec{
ProjectID: state.ProjectID,
CommitmentUUID: state.CommitmentUUID,
DomainID: state.DomainID,
ResourceGroup: state.FlavorGroupName,
ResourceName: candidate.FlavorName,
Creator: creator,
ParentGeneration: state.ParentGeneration,
Allocations: map[string]v1alpha1.CommittedResourceAllocation{
candidate.VMID: {
CreationTimestamp: metav1.Now(),
+ Resources: map[hv1.ResourceName]resource.Quantity{
+ hv1.ResourceMemory: *resource.NewQuantity(memoryBytes, resource.BinarySI),
+ hv1.ResourceCPU: *resource.NewQuantity(cpus, resource.DecimalSI),
+ },
},
},
},
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/scheduling/reservations/commitments/reservation_manager.go` around
lines 535 - 538, In the newPaygReservation function where
CommittedResourceAllocation is initialized for candidate.VMID in the Allocations
map, add the required Resources field in addition to the existing
CreationTimestamp. The Resources field should be a map that specifies the
committed resources for the allocation to satisfy API validation requirements
for PAYG pre-allocations.
Test Coverage ReportTest Coverage 📊: 69.8% |
When a new committed resource is created, the controller now absorbs existing PAYG VMs into reservation slots instead of blindly probing the scheduler for every slot.