Skip to content

Commit f323edb

Browse files
authored
fix: circular dependency when resource kind order changes between spec and state (#1406)
1 parent bd7c55f commit f323edb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/engine/operation/parser/parser.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
v1 "kusionstack.io/kusion/pkg/apis/status/v1"
99
"kusionstack.io/kusion/pkg/engine/operation/graph"
1010
"kusionstack.io/kusion/pkg/engine/operation/models"
11+
"kusionstack.io/kusion/pkg/log"
1112
"kusionstack.io/kusion/third_party/terraform/dag"
1213
)
1314

@@ -73,13 +74,21 @@ func LinkRefNodes(
7374
if ag.HasVertex(parentNode) {
7475
parentNode = GetVertex(ag, baseNode).(*graph.ResourceNode)
7576
ag.Connect(dag.BasicEdge(rn, parentNode))
77+
if cycles := ag.Cycles(); len(cycles) > 0 {
78+
ag.RemoveEdge(dag.BasicEdge(rn, parentNode))
79+
log.Debug("Found cycle in graph when merging, removing edge")
80+
}
7681
} else {
7782
ag.Add(parentNode)
7883
ag.Connect(dag.BasicEdge(rn, parentNode))
7984
}
8085
} else {
8186
parentNode = GetVertex(ag, baseNode).(*graph.ResourceNode)
8287
ag.Connect(dag.BasicEdge(parentNode, rn))
88+
if cycles := ag.Cycles(); len(cycles) > 0 {
89+
ag.RemoveEdge(dag.BasicEdge(parentNode, rn))
90+
log.Debug("Found cycle in graph when merging, removing edge")
91+
}
8392
}
8493
default:
8594
hasParent := ag.HasVertex(parentNode)

0 commit comments

Comments
 (0)