Skip to content

fix(reconciler): nodeHasCapacity uses wrong variable semantics #158

Description

@Anhydrite

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions