Skip to content

Commit

Permalink
fix: simplify logic with NoMatcher
Browse files Browse the repository at this point in the history
Signed-off-by: Hunter Gregory <[email protected]>
  • Loading branch information
huntergregory committed Jul 19, 2024
1 parent 8962e94 commit 2ab5e82
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/policy-assistant/pkg/matcher/simplifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ func SimplifyV1(matchers []PeerMatcher) []PeerMatcher {
}
}

if len(v1Matchers) == 0 {
return nil
}

onlyNoMatchers := true
for _, matcher := range v1Matchers {
if _, ok := matcher.(*NoMatcher); !ok {
onlyNoMatchers = false
break
}
}

if onlyNoMatchers {
return []PeerMatcher{&NoMatcher{}}
}

matchesAll := false
var portsForAllPeersMatchers []*PortsForAllPeersMatcher
var ips []*IPPeerMatcher
Expand All @@ -47,6 +63,8 @@ func SimplifyV1(matchers []PeerMatcher) []PeerMatcher {
ips = append(ips, a)
case *PodPeerMatcher:
pods = append(pods, a)
case *NoMatcher:
// nothing to do
default:
panic(errors.Errorf("invalid matcher type %T", matcher))
}
Expand Down

0 comments on commit 2ab5e82

Please sign in to comment.