Skip to content

Commit

Permalink
Rename PrefixSuffixMatch to WildcardMatch
Browse files Browse the repository at this point in the history
open-policy-agent#1796 (comment)

Signed-off-by: Sunghoon Kang <hoon@linecorp.com>
  • Loading branch information
Sunghoon Kang committed Jan 19, 2022
1 parent 70b73bb commit 17fa858
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/controller/config/process/excluder.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ func (s *Excluder) IsNamespaceExcluded(process Process, obj runtime.Object) (boo
}

if obj.GetObjectKind().GroupVersionKind().Kind == "Namespace" && obj.GetObjectKind().GroupVersionKind().Group == "" {
return exactOrPrefixSuffixMatch(s.excludedNamespaces[process], meta.GetName()), nil
return exactOrWildcardMatch(s.excludedNamespaces[process], meta.GetName()), nil
}

return exactOrPrefixSuffixMatch(s.excludedNamespaces[process], meta.GetNamespace()), nil
return exactOrWildcardMatch(s.excludedNamespaces[process], meta.GetNamespace()), nil
}

func exactOrPrefixSuffixMatch(boolMap map[util.Wildcard]bool, ns string) bool {
func exactOrWildcardMatch(boolMap map[util.Wildcard]bool, ns string) bool {
for k := range boolMap {
if k.Matches(ns) {
return true
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/config/process/excluder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/open-policy-agent/gatekeeper/pkg/util"
)

func TestExactOrPrefixSuffixMatch(t *testing.T) {
func TestExactOrWildcardMatch(t *testing.T) {
tcs := []struct {
name string
nsMap map[util.Wildcard]bool
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestExactOrPrefixSuffixMatch(t *testing.T) {

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
if exactOrPrefixSuffixMatch(tc.nsMap, tc.ns) != tc.excluded {
if exactOrWildcardMatch(tc.nsMap, tc.ns) != tc.excluded {
if tc.excluded {
t.Errorf("Expected ns '%v' to match map: %v", tc.ns, tc.nsMap)
} else {
Expand Down

0 comments on commit 17fa858

Please sign in to comment.