feat: add glob pattern support for --namespace flag#1247
feat: add glob pattern support for --namespace flag#1247majiayu000 wants to merge 3 commits intoopen-policy-agent:masterfrom
Conversation
Add support for glob-style wildcards (*, ?, [...]) in the --namespace flag, allowing users to match multiple namespaces with patterns like "main.*" or "*.gke". Fixes open-policy-agent#1141 Signed-off-by: majiayu000 <1835304752@qq.com>
Rename "Test command with namespace wildcard pattern" to "Test command with namespace exact match" since it tests exact namespace matching without wildcards. Signed-off-by: majiayu000 <1835304752@qq.com>
jalseth
left a comment
There was a problem hiding this comment.
Thanks for taking on this PR. Can you also add support to this for the verify command?
runner/test.go
Outdated
| // filterNamespaces filters the available namespaces using the given patterns. | ||
| // Patterns support glob-style matching with *, ?, and [...] syntax. | ||
| func filterNamespaces(available []string, patterns []string) []string { | ||
| seen := make(map[string]bool) |
There was a problem hiding this comment.
I don't think this is necessary. engine.Namespaces() returns the unique list already.
runner/test.go
Outdated
| } | ||
| matched, err := path.Match(pattern, ns) | ||
| if err != nil { | ||
| continue |
There was a problem hiding this comment.
This should raise an error rather than silently continuing.
| } | ||
| } | ||
|
|
||
| func TestFilterNamespaces(t *testing.T) { |
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { |
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { |
| "testing" | ||
| ) | ||
|
|
||
| func TestHasWildcard(t *testing.T) { |
| return files, nil | ||
| } | ||
|
|
||
| // hasWildcard checks if any of the given patterns contain wildcard characters. |
There was a problem hiding this comment.
Please add a note that this is based on what path.Match() supports.
runner/test.go
Outdated
| } | ||
|
|
||
| // filterNamespaces filters the available namespaces using the given patterns. | ||
| // Patterns support glob-style matching with *, ?, and [...] syntax. |
There was a problem hiding this comment.
Please add a note that this is based on what path.Match() supports.
| // Patterns support glob-style matching with *, ?, and [...] syntax. | ||
| func filterNamespaces(available []string, patterns []string) []string { | ||
| seen := make(map[string]bool) | ||
| var result []string |
There was a problem hiding this comment.
nit: Call this namespaces rather than a generic variable name.
|
@majiayu000 Is this still being worked on? |
Signed-off-by: Gemini <gemini@google.com>
|
Thanks for the review @jalseth! I've updated the PR to include support for the |
Fixes #1141
Changes