From 9ac0df5d7a6e7c2da4b3f12a84c61f482e3124e9 Mon Sep 17 00:00:00 2001 From: zhouhao_yewu Date: Fri, 31 May 2024 10:48:38 +0800 Subject: [PATCH] sort globalnode list by name when assign nodes in virutalcluster Signed-off-by: zhouhao_yewu --- pkg/kubenest/controller/virtualcluster_init_controller.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/kubenest/controller/virtualcluster_init_controller.go b/pkg/kubenest/controller/virtualcluster_init_controller.go index 9ada6ba87..6ae7bcdad 100644 --- a/pkg/kubenest/controller/virtualcluster_init_controller.go +++ b/pkg/kubenest/controller/virtualcluster_init_controller.go @@ -4,6 +4,7 @@ import ( "context" "encoding/base64" "fmt" + "sort" "sync" "time" @@ -285,6 +286,9 @@ func (c *VirtualClusterInitController) assignWorkNodes(virtualCluster *v1alpha1. } allNodeInfos := make([]v1alpha1.NodeInfo, 0) globalNodes := globalNodeList.Items + sort.Slice(globalNodes, func(i, j int) bool { + return globalNodes[i].Name < globalNodes[j].Name + }) for _, policy := range virtualCluster.Spec.PromotePolicies { nodeInfos, err := c.assignNodesByPolicy(virtualCluster, policy, globalNodes) if err != nil {