From 8546a03e6058dfca6d1b4ae669cc7d5174aa7cb3 Mon Sep 17 00:00:00 2001 From: "cortex-ai-agents[bot]" <279748396+cortex-ai-agents[bot]@users.noreply.github.com> Date: Mon, 20 Jul 2026 07:15:38 +0000 Subject: [PATCH] fix: deep-copy capacity map to prevent informer cache corruption The capacity filter assigned hypervisor Status.Capacity map references directly into a local working map, then mutated those maps during free-resource calculations. Since the maps are shared with the controller-runtime informer cache, each scheduling pass permanently decremented cached capacity values, progressively starving scheduling until all hosts appeared full. Fix: deep-copy the capacity map per hypervisor before subtracting allocations so the informer cache is never mutated. Co-Authored-By: Claude Opus 4.7 --- .../plugins/filters/filter_has_enough_capacity.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/scheduling/nova/plugins/filters/filter_has_enough_capacity.go b/internal/scheduling/nova/plugins/filters/filter_has_enough_capacity.go index e2fadf981..117b032ae 100644 --- a/internal/scheduling/nova/plugins/filters/filter_has_enough_capacity.go +++ b/internal/scheduling/nova/plugins/filters/filter_has_enough_capacity.go @@ -82,13 +82,20 @@ func (s *FilterHasEnoughCapacity) Run(traceLog *slog.Logger, request api.Externa return nil, err } for _, hv := range hvs.Items { + var sourceMap map[hv1.ResourceName]resource.Quantity 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 + sourceMap = hv.Status.Capacity } else { // Start with the total effective capacity which is capacity * overcommit ratio. - freeResourcesByHost[hv.Name] = hv.Status.EffectiveCapacity + sourceMap = hv.Status.EffectiveCapacity } + // Deep-copy the map to avoid mutating the informer cache. + copied := make(map[hv1.ResourceName]resource.Quantity, len(sourceMap)) + for k, v := range sourceMap { + copied[k] = v.DeepCopy() + } + freeResourcesByHost[hv.Name] = copied // Subtract allocated resources (skip when ignoring allocations for empty-datacenter capacity queries). if !ignoreAllocations {