From d4700d32d656a560712c27b3212b19224eda01e1 Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Wed, 6 Dec 2023 15:01:41 +0800 Subject: [PATCH] fix(replica-auto-balance): loop when node has no schedulable disk ref: 6508 Signed-off-by: Chin-Ya Huang --- datastore/longhorn.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/datastore/longhorn.go b/datastore/longhorn.go index 5ce73f4911..62e50b678b 100644 --- a/datastore/longhorn.go +++ b/datastore/longhorn.go @@ -2480,11 +2480,24 @@ func filterReadyNodes(nodes map[string]*longhorn.Node) map[string]*longhorn.Node }) } -// filterSchedulableNodes returns only the nodes that are ready +// filterSchedulableNodes returns only the nodes that are ready and have at least one schedulable disk func filterSchedulableNodes(nodes map[string]*longhorn.Node) map[string]*longhorn.Node { return filterNodes(nodes, func(node *longhorn.Node) bool { nodeSchedulableCondition := types.GetCondition(node.Status.Conditions, longhorn.NodeConditionTypeSchedulable) - return nodeSchedulableCondition.Status == longhorn.ConditionStatusTrue + if nodeSchedulableCondition.Status != longhorn.ConditionStatusTrue { + return false + } + + for _, disk := range node.Spec.Disks { + if disk.EvictionRequested { + continue + } + + if disk.AllowScheduling { + return true + } + } + return false }) }