From 806aafd75e55cac54dbabb055cc42ceba6ef87db Mon Sep 17 00:00:00 2001 From: "xuesongzuo@yunify.com" Date: Mon, 8 Dec 2025 13:04:43 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E4=B8=BB=E6=9C=BA=E5=88=86=E7=BB=84?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E8=BF=87=E6=B7=B1=EF=BC=8C=E5=B9=B6=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E6=AD=BB=E5=BE=AA=E7=8E=AF=E7=9A=84host=E5=88=86?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuesongzuo@yunify.com bugfix: 主机分组不可过深,并防止死循环的host分组 Signed-off-by: xuesongzuo@yunify.com bugfix: 主机分组不可过深,并防止死循环的host分组 Signed-off-by: xuesongzuo@yunify.com bugfix: 主机分组不可过深,并防止死循环的host分组 Signed-off-by: xuesongzuo@yunify.com --- pkg/variable/helper.go | 5 +++-- pkg/variable/helper_test.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/variable/helper.go b/pkg/variable/helper.go index e198de54..44f1ba70 100644 --- a/pkg/variable/helper.go +++ b/pkg/variable/helper.go @@ -25,7 +25,6 @@ import ( "github.com/cockroachdb/errors" kkcorev1 "github.com/kubesphere/kubekey/api/core/v1" - "github.com/kubesphere/kubekey/v4/pkg/utils" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/json" @@ -34,6 +33,7 @@ import ( _const "github.com/kubesphere/kubekey/v4/pkg/const" "github.com/kubesphere/kubekey/v4/pkg/converter/tmpl" + "github.com/kubesphere/kubekey/v4/pkg/utils" ) // CombineVariables merge multiple variables into one variable. @@ -176,7 +176,8 @@ func hostsInGroup(inv kkcorev1.Inventory, groupName string, groupsGraph *utils.K for _, cg := range v.Groups { if groupsGraph != nil { if groupsGraph.AddEdgeAndCheckCycle(groupName, cg) { - continue + klog.Warningf("group host found cycle by %s -> %s", groupName, cg) + return []string{} } } hosts = CombineSlice(hostsInGroup(inv, cg, groupsGraph), hosts) diff --git a/pkg/variable/helper_test.go b/pkg/variable/helper_test.go index 29db7b40..64b8f6bb 100644 --- a/pkg/variable/helper_test.go +++ b/pkg/variable/helper_test.go @@ -22,6 +22,8 @@ import ( kkcorev1 "github.com/kubesphere/kubekey/api/core/v1" "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/runtime" + + "github.com/kubesphere/kubekey/v4/pkg/utils" ) func TestCombineSlice(t *testing.T) { @@ -126,7 +128,7 @@ func TestHostsInGroup(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - assert.ElementsMatch(t, tc.except, hostsInGroup(tc.inventory, tc.groupName, nil)) + assert.ElementsMatch(t, tc.except, hostsInGroup(tc.inventory, tc.groupName, utils.NewKahnGraph())) }) } }