Fix: Schedule vms evenly across nodes when memory allows #585
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
No issue raised
Description of changes:
This PR fixes a scheduling imbalance in the VM scheduler logic. Previously, when one node had fewer replicas than others but lacked sufficient available memory, the scheduler would always select the node with the most free memory. This behavior caused an uneven distribution of replicas across nodes.
The updated logic ensures that replicas are spread more evenly across nodes, provided memory constraints are satisfied.
See the affected logic below, where the scheduler performs round-robin scheduling only if the node with the fewest replicas has sufficient available memory:
https://github.com/ionos-cloud/cluster-api-provider-proxmox/blob/92ac7a597d57a5a56c0024b02f389c33f423c3fc/internal/service/scheduler/vmscheduler.go#L111C1-L115C3
Testing performed: