Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Linking policies to other objects #43

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading