feat: Add fallback to capacity filter and external customer filter#593
feat: Add fallback to capacity filter and external customer filter#593
Conversation
📝 WalkthroughWalkthroughThis PR modifies Nova scheduling filter error handling and capacity fallback logic. When domain_name scheduler hints are unavailable, the external customer filter now logs and gracefully skips instead of returning an error. Additionally, when a hypervisor's EffectiveCapacity is nil, capacity filtering now falls back to using Capacity for calculations instead of skipping the host. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip You can disable the changed files summary in the walkthrough.Disable the |
Test Coverage ReportTest Coverage 📊: 69.6% |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/scheduling/nova/plugins/filters/filter_has_enough_capacity.go (1)
59-65: Inconsistent resource map handling—consider deep copying for consistency with reservation pattern.The current code safely handles resource quantity mutations through a retrieve-modify-reassign pattern (lines 69–78), so the original Capacity and EffectiveCapacity maps are not mutated. However, the hypervisor resource initialization (lines 61, 64) assigns map descriptors directly, which is inconsistent with the reservation handling pattern elsewhere in the file (lines 162–165), where a new map is created and values are explicitly deep copied.
For consistency and defensive programming, consider adopting the same deep copy pattern used for reservations:
Proposed change for consistency
if hv.Status.EffectiveCapacity == nil { traceLog.Warn("hypervisor with nil effective capacity, use capacity instead (overprovisioning not considered)", "host", hv.Name) - freeResourcesByHost[hv.Name] = hv.Status.Capacity + freeResourcesByHost[hv.Name] = make(map[hv1.ResourceName]resource.Quantity) + for k, v := range hv.Status.Capacity { + freeResourcesByHost[hv.Name][k] = v.DeepCopy() + } } else { // Start with the total effective capacity which is capacity * overcommit ratio. - freeResourcesByHost[hv.Name] = hv.Status.EffectiveCapacity + freeResourcesByHost[hv.Name] = make(map[hv1.ResourceName]resource.Quantity) + for k, v := range hv.Status.EffectiveCapacity { + freeResourcesByHost[hv.Name][k] = v.DeepCopy() + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/scheduling/nova/plugins/filters/filter_has_enough_capacity.go` around lines 59 - 65, The initialization assigns hv.Status.Capacity or hv.Status.EffectiveCapacity map descriptors directly into freeResourcesByHost[hv.Name], risking shared-mutation; change both branches to allocate a new map and deep-copy each resource key/value into it (same pattern used for reservation handling where a fresh map is created and values copied), i.e., when hv.Status.EffectiveCapacity == nil copy from hv.Status.Capacity into a new map, otherwise copy from hv.Status.EffectiveCapacity into a new map before assigning to freeResourcesByHost[hv.Name]; keep traceLog.Warn as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/scheduling/nova/plugins/filters/filter_has_enough_capacity.go`:
- Around line 59-65: The initialization assigns hv.Status.Capacity or
hv.Status.EffectiveCapacity map descriptors directly into
freeResourcesByHost[hv.Name], risking shared-mutation; change both branches to
allocate a new map and deep-copy each resource key/value into it (same pattern
used for reservation handling where a fresh map is created and values copied),
i.e., when hv.Status.EffectiveCapacity == nil copy from hv.Status.Capacity into
a new map, otherwise copy from hv.Status.EffectiveCapacity into a new map before
assigning to freeResourcesByHost[hv.Name]; keep traceLog.Warn as-is.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a2418bec-03f7-4d18-8cfe-e65271bb189a
📒 Files selected for processing (4)
internal/scheduling/nova/plugins/filters/filter_external_customer.gointernal/scheduling/nova/plugins/filters/filter_external_customer_test.gointernal/scheduling/nova/plugins/filters/filter_has_enough_capacity.gointernal/scheduling/nova/plugins/filters/filter_has_enough_capacity_test.go
No description provided.