Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 80d4f7e

Browse files
committed
better use mustcompile and convert includedNamespacesRegex to Regexp type
1 parent 95f5025 commit 80d4f7e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

internal/config/default_config.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package config
22

3+
import "regexp"
4+
35
// UnpropgatedAnnotations is a list of annotations on objects that should _not_ be propagated by HNC.
46
// Much like HNC itself, other systems (such as GKE Config Sync) use annotations to "claim" an
57
// object - such as deleting objects it doesn't recognize. By removing these annotations on
@@ -15,4 +17,4 @@ var UnpropagatedAnnotations []string
1517
// This value is controlled by the --excluded-namespace command line, which may
1618
// be set multiple times.
1719
var excludedNamespaces map[string]bool
18-
var includedNamespacesRegex string
20+
var includedNamespacesRegex *regexp.Regexp

internal/config/namespace.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func SetNamespaces(regex string, excluded ...string) {
1010
regex = ".*"
1111
}
1212

13-
includedNamespacesRegex = regex
13+
includedNamespacesRegex = regexp.MustCompile("^" + regex + "$")
1414

1515
excludedNamespaces = make(map[string]bool)
1616
for _, exn := range excluded {
@@ -25,8 +25,6 @@ func IsNamespaceIncluded(name string) bool {
2525
return false
2626
}
2727

28-
regex, _ := regexp.Compile("^" + includedNamespacesRegex + "$")
29-
30-
return regex.MatchString(name)
28+
return includedNamespacesRegex.MatchString(name)
3129

3230
}

0 commit comments

Comments
 (0)