[match]: Add glob matcher for routing rules#52
Open
pseudomuto wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #52 +/- ##
==========================================
+ Coverage 85.12% 85.44% +0.32%
==========================================
Files 33 34 +1
Lines 1042 1079 +37
==========================================
+ Hits 887 922 +35
- Misses 131 133 +2
Partials 24 24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a small pkg/match helper to compile and apply a constrained “glob” syntax used by routing rules (namespace/metadata matching), intentionally avoiding full glob/regexp semantics.
Changes:
- Introduces
pkg/match.MatcherwithCompile/MustCompileandMatchfor literal/prefix/suffix/contains matching. - Adds unit tests covering supported forms, match-all patterns, and rejection of embedded
*. - Adds package-level documentation describing the supported pattern forms.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/match/match.go | Implements the compiled matcher, pattern compilation/validation, and matching logic. |
| pkg/match/match_test.go | Adds tests for matcher behavior and invalid pattern rejection. |
| pkg/match/doc.go | Documents the supported matching forms for operator-authored patterns. |
Routing rules (RFC #32) match namespaces and metadata values using simple globs: exact, prefix (foo*), suffix (*foo), and contains (*foo*). This adds a small, dependency-free pkg/match that compiles a pattern once and matches against it. The implementation deliberately supports only those four forms and rejects an interior "*" (e.g. "a*b") at compile time, so a malformed pattern fails fast at config-load rather than silently matching the wrong thing. A general globber (e.g. path.Match, regexp) was avoided on purpose: those assign meaning to "?", "[]", "\", and treat "/" as a separator, which would change behavior for operator-authored patterns and arbitrary metadata values.
22520f0 to
c236f2a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Routing rules (RFC #32) match namespaces and metadata values using simple globs: exact, prefix (
foo*), suffix (*foo), and contains (*foo*). This adds a small, dependency-free pkg/match that compiles a pattern once and matches against it.The implementation deliberately supports only those four forms and rejects an interior "" (e.g., "ab") at compile time, so a malformed pattern fails fast at config load rather than silently matching the wrong thing. A general globber (e.g.
path.Match,regexp) was avoided on purpose: those assign meaning to "?", "[]", "", and treat "/" as a separator, which would change behaviour for operator-authored patterns and arbitrary metadata values.