Skip to content

Commit

Permalink
Merge pull request #43 from Kuadrant/fix_policy_linking
Browse files Browse the repository at this point in the history
fix: Linking policies to other objects
  • Loading branch information
mikenairn authored Oct 21, 2024
2 parents db72801 + 2dc665c commit 0cb371b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions machinery/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func NewTopology(options ...TopologyOptionsFunc) (*Topology, error) {

addObjectsToGraph(graph, o.Objects)
addTargetablesToGraph(graph, targetables)
addPoliciesToGraph(graph, policies)

linkables := append(o.Objects, lo.Map(targetables, AsObject[Targetable])...)
linkables = append(linkables, lo.Map(policies, AsObject[Policy])...)
Expand All @@ -118,8 +119,6 @@ func NewTopology(options ...TopologyOptionsFunc) (*Topology, error) {
}
}

addPoliciesToGraph(graph, policies)

var err error
if !o.AllowLoops && !isDAG(graph) {
err = errors.New("loop detected in the graph, check linking functions")
Expand Down
5 changes: 4 additions & 1 deletion machinery/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ func TestTopologyAll(t *testing.T) {
objects := []*Info{
{Name: "info-1", Ref: "apple.example.test:apple-1"},
{Name: "info-2", Ref: "orange.example.test:my-namespace/orange-1"},
{Name: "info-3", Ref: "fruitpolicy.test:my-namespace/policy-1"},
}
apples := []*Apple{{Name: "apple-1"}}
oranges := []*Orange{
Expand Down Expand Up @@ -543,6 +544,7 @@ func TestTopologyAll(t *testing.T) {
LinkApplesToOranges(apples),
LinkInfoFrom("Apple", lo.Map(apples, AsObject[*Apple])),
LinkInfoFrom("Orange", lo.Map(oranges, AsObject[*Orange])),
LinkInfoFrom("Policy", lo.Map(policies, AsObject[Policy])),
),
)

Expand All @@ -553,13 +555,14 @@ func TestTopologyAll(t *testing.T) {
SaveToOutputDir(t, topology.ToDot(), "../tests/out", ".dot")

expectedLinks := map[string][]string{
"policy-1": {"apple-1"},
"policy-1": {"apple-1", "info-3"},
"policy-2": {"orange-1"},
"apple-1": {"orange-1", "orange-2", "info-1"},
"orange-1": {"info-2"},
"orange-2": {},
"info-1": {},
"info-2": {},
"info-3": {},
}

links := make(map[string][]string)
Expand Down

0 comments on commit 0cb371b

Please sign in to comment.