Problem
In the reconciler's nodeHasCapacity function, the variable named freeCPU actually stores used_cpu from the database, which inverts the comparison logic.
Current Code
File: /root/AnhyWhere/internal/cluster/reconciler.go (lines 385-414)
The Bug
The comparison logic is inverted:
- If
usedCPU = 8 and needCPU = 2, then freeCPU (8) < needCPU (2) is false, so it returns true (allowing dispatch)
- But the actual available CPU should be
totalCPU - usedCPU, not just usedCPU
This means:
- Nodes with HIGH usage are incorrectly allowed to receive new VMs
- Nodes with LOW usage are incorrectly blocked
Expected Behavior
Impact
VMs may be dispatched to already-full nodes, causing:
- VM startup failures
- Resource exhaustion
- Potential crashes on the target node
Priority
Medium — This is a correctness bug but the optimistic fallback (return true on error) partially masks it in practice.
Problem
In the reconciler's
nodeHasCapacityfunction, the variable namedfreeCPUactually storesused_cpufrom the database, which inverts the comparison logic.Current Code
File: /root/AnhyWhere/internal/cluster/reconciler.go (lines 385-414)
The Bug
The comparison logic is inverted:
usedCPU = 8andneedCPU = 2, thenfreeCPU (8) < needCPU (2)is false, so it returns true (allowing dispatch)totalCPU - usedCPU, not justusedCPUThis means:
Expected Behavior
Impact
VMs may be dispatched to already-full nodes, causing:
Priority
Medium — This is a correctness bug but the optimistic fallback (return true on error) partially masks it in practice.