Browse Source

Admit "<cluster>" when parsing ResourceIDs

The PR #1442 introduce code to determine which namespace, if any, each
manifest belongs to. To distinguish between resources that need a
namespace but don't have one, and resources that are cluster-scoped,
it introduced the sentinel value `<cluster>` for the latter.

Regrettably, I didn't accompany this with code for _parsing_ those
sentinel values, since I reasoned that it would only be used
internally. But the sync events generated by fluxd include a list of
changed resources, and those inevitably will include things like
namespaces that are cluster-scoped. The result is that fluxd will
generate events that cannot then be parsed by the receiver.

This commit fixes that by recognising `<cluster>` as a namespace when
parsing resource IDs.
Michael Bridgen 6 months ago
parent
commit
74575ae753
2 changed files with 3 additions and 2 deletions
  1. 2
    2
      flux.go
  2. 1
    0
      resourceid_test.go

+ 2
- 2
flux.go View File

@@ -14,12 +14,12 @@ var (
14 14
 	ErrInvalidServiceID = errors.New("invalid service ID")
15 15
 
16 16
 	LegacyServiceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$")
17
-	// The namespace and name commponents are (apparently
17
+	// The namespace and name components are (apparently
18 18
 	// non-normatively) defined in
19 19
 	// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/identifiers.md
20 20
 	// In practice, more punctuation is used than allowed there;
21 21
 	// specifically, people use underscores as well as dashes and dots, and in names, colons.
22
-	ResourceIDRegexp            = regexp.MustCompile("^([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
22
+	ResourceIDRegexp            = regexp.MustCompile("^(<cluster>|[a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
23 23
 	UnqualifiedResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
24 24
 )
25 25
 

+ 1
- 0
resourceid_test.go View File

@@ -14,6 +14,7 @@ func TestResourceIDParsing(t *testing.T) {
14 14
 		{"dots", "namespace:kind/name.with.dots"},
15 15
 		{"colons", "namespace:kind/name:with:colons"},
16 16
 		{"punctuation in general", "name-space:ki_nd/punc_tu:a.tion-rules"},
17
+		{"cluster-scope resource", "<cluster>:namespace/foo"},
17 18
 	}
18 19
 	invalid := []test{
19 20
 		{"unqualified", "justname"},

Loading…
Cancel
Save