Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Admit "<cluster>" when parsing ResourceIDs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
squaremo committed Mar 21, 2019
1 parent 88402e3 commit 74575ae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ var (
ErrInvalidServiceID = errors.New("invalid service ID")

LegacyServiceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$")
// The namespace and name commponents are (apparently
// The namespace and name components are (apparently
// non-normatively) defined in
// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/identifiers.md
// In practice, more punctuation is used than allowed there;
// specifically, people use underscores as well as dashes and dots, and in names, colons.
ResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
ResourceIDRegexp = regexp.MustCompile("^(<cluster>|[a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
UnqualifiedResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
)

Expand Down
1 change: 1 addition & 0 deletions resourceid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestResourceIDParsing(t *testing.T) {
{"dots", "namespace:kind/name.with.dots"},
{"colons", "namespace:kind/name:with:colons"},
{"punctuation in general", "name-space:ki_nd/punc_tu:a.tion-rules"},
{"cluster-scope resource", "<cluster>:namespace/foo"},
}
invalid := []test{
{"unqualified", "justname"},
Expand Down

0 comments on commit 74575ae

Please sign in to comment.