feat: cleanup candidate reservations when confirming vm - #871
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)
📝 WalkthroughWalkthroughThe PR adds a Reservation field index keyed by allocation VM UUIDs, updates the controller to remove newly confirmed VM UUIDs from candidate reservations using that index, registers the index in test environments, and adds tests validating cleanup behavior. ChangesReservation Allocation Cleanup by VM UUID
Sequence Diagram(s)sequenceDiagram
participant Reconciler as reconcileAllocations
participant Status as Status.Allocations snapshot
participant Cleanup as cleanupCandidateReservations
participant Index as Reservation VM-UUID Index
participant Candidate as Candidate Reservation CRs
Reconciler->>Status: snapshot old allocations
Reconciler->>Reconciler: compute newStatusAllocations
Reconciler->>Cleanup: for each newly confirmed VM UUID
Cleanup->>Index: list reservations by VM UUID
Index-->>Cleanup: candidate reservations
Cleanup->>Candidate: patch Spec.CommittedResourceReservation.Allocations (remove VM UUID)
Candidate-->>Cleanup: patch result
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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: 1
🤖 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/reservation_controller.go`:
- Around line 398-403: The current logic copies
res.Status.CommittedResourceReservation.Allocations into
existingStatusAllocations and later uses presence in status to skip cleanup,
which allows a transient cleanup failure to be permanently skipped on the next
reconcile; change the reconcile/cleanup flow in reservation_controller.go so
cleanup of stale candidate allocations is not gated solely by membership in
res.Status.CommittedResourceReservation.Allocations: compare
existingStatusAllocations to the new patched allocations and only mark candidate
allocations removed when the cleanup step actually succeeded, and if the
patch/cleanup fails do not mutate status to record the VM as cleaned;
specifically update the code that reads/writes
res.Status.CommittedResourceReservation.Allocations and the cleanup branch (the
blocks around existingStatusAllocations and the cleanup calls referenced in your
comment) to always retry cleanup for VMs whose candidate allocations remain
stale until cleanup returns success (or add an explicit per-VM cleanup-needed
flag/finalizer in status that you clear only after successful cleanup).
🪄 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: 8d9d8ac7-752f-4ae0-bbfc-99d65b9ce8b2
📒 Files selected for processing (5)
internal/scheduling/reservations/commitments/committed_resource_controller_test.gointernal/scheduling/reservations/commitments/field_index.gointernal/scheduling/reservations/commitments/integration_test.gointernal/scheduling/reservations/commitments/reservation_controller.gointernal/scheduling/reservations/commitments/reservation_controller_test.go
Test Coverage ReportTest Coverage 📊: 69.5% |
PR #871 added proactive candidate reservation cleanup when a VM is confirmed on a reservation. When a VM transitions from Spec-only to Spec+Status (newly confirmed on the expected host), the controller immediately removes that VM's UUID from Spec.Allocations on all other candidate reservations. This frees phantom capacity blocks on non-selected hosts immediately rather than waiting for each candidate's grace period expiry or periodic requeue. This behavior was undocumented. Assisted-by: Claude Code:claude-sonnet-4-20250514 [Bash] [Read] Co-authored-by: cortex-ai-agents[bot] <279748396+cortex-ai-agents[bot]@users.noreply.github.com>
## 2026-06-08 — [#919](#919) ### cortex v0.1.0 (sha-a0373875) Breaking changes: - `Client.AddRemote()` signature changed — added `insecureSkipTLSVerify bool` parameter between `caCert` and `labels`. Any external caller of `pkg/multicluster.Client.AddRemote` must update their call site. ([#911](#911)) Non-breaking changes: - Cleanup candidate reservations when confirming VM ([#871](#871)) - Add `InsecureSkipTLSVerify` option to multicluster `RemoteConfig` ([#911](#911)) - Add KVM HANA stacking KPI ([#905](#905)) - Preserve input weight ordering when no weighers are configured ([#918](#918)) - Make nova alerts region- and value-aware ([#902](#902)) - Update cpu steal time query ([#904](#904)) - Bump datasource parallel reconciles to 3 to reduce queue lag ([#907](#907)) - Move `prometheusDatasourceControllerParallelReconciles` value from secrets to bundle ([#912](#912)) - Update `github.com/sapcc/go-bits` ([#903](#903), [#913](#913), [#915](#915)) - Update External dependencies ([#908](#908), [#910](#910), [#914](#914)) - Update kube-prometheus-stack Docker tag to v86 ([#895](#895)) ### cortex-crds v0.0.74 Includes updated chart cortex v0.1.0. ### cortex-nova v0.0.74 Includes updated chart cortex v0.1.0. ### cortex-cinder v0.0.74 Includes updated chart cortex v0.1.0. ### cortex-pods v0.0.74 Includes updated chart cortex v0.1.0. ### cortex-ironcore v0.0.74 Includes updated chart cortex v0.1.0. ### cortex-manila v0.0.74 Includes updated chart cortex v0.1.0. --- **Related PRs:** - Bump PR: [#920](#920) - Changelog PR: [#921](#921)
PR #871 added proactive candidate reservation cleanup when a VM is confirmed on a reservation. When a VM transitions from Spec-only to Spec+Status (newly confirmed on the expected host), the controller immediately removes that VM's UUID from Spec.Allocations on all other candidate reservations. This frees phantom capacity blocks on non-selected hosts immediately rather than waiting for each candidate's grace period expiry or periodic requeue. This behavior was undocumented. Assisted-by: Claude Code:claude-sonnet-4-20250514 [Bash] [Read] Co-authored-by: cortex-ai-agents[bot] <279748396+cortex-ai-agents[bot]@users.noreply.github.com>
When a VM is confirmed onto a CommittedResource reservation, immediately
remove that VM's UUID from Spec.Allocations on all other candidate
reservations that still carry it. Previously those slots were only freed
after their grace period or the next periodic requeue, leaving transient
phantom blocks on non-selected hosts.