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

Allow colons in the name component of resource IDs #1282

Merged
merged 1 commit into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ import (
var (
ErrInvalidServiceID = errors.New("invalid service ID")

LegacyServiceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$")
ResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.-]+)$")
UnqualifiedResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.-]+)$")
LegacyServiceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$")
// The namespace and name commponents 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_.:-]+)$")
UnqualifiedResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
)

// ResourceID is an opaque type which uniquely identifies a resource in an
Expand Down
38 changes: 38 additions & 0 deletions resourceid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package flux

import (
"testing"
)

func TestResourceIDParsing(t *testing.T) {
type test struct {
name, id string
}
valid := []test{
{"full", "namespace:kind/name"},
{"legacy", "namespace/service"},
{"dots", "namespace:kind/name.with.dots"},
{"colons", "namespace:kind/name:with:colons"},
{"punctuation in general", "name-space:ki_nd/punc_tu:a.tion-rules"},

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

}
invalid := []test{
{"unqualified", "justname"},
{"dots in namespace", "name.space:kind/name"},
{"too many colons", "namespace:kind:name"},
}

for _, tc := range valid {
t.Run(tc.name, func(t *testing.T) {
if _, err := ParseResourceID(tc.id); err != nil {
t.Error(err)
}
})
}
for _, tc := range invalid {
t.Run(tc.name, func(t *testing.T) {
if _, err := ParseResourceID(tc.id); err == nil {
t.Errorf("expected %q to be considered invalid", tc.id)
}
})
}
}