forked from operator-framework/catalogd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable CatalogMetadataAPI via explicit flag, fix syncing issues (oper…
- Loading branch information
1 parent
64a9fe5
commit f1067da
Showing
7 changed files
with
124 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package k8sutil | ||
|
||
import ( | ||
"regexp" | ||
|
||
"k8s.io/apimachinery/pkg/util/validation" | ||
) | ||
|
||
var invalidNameChars = regexp.MustCompile(`[^\.\-a-zA-Z0-9]`) | ||
|
||
// MetadataName replaces all invalid DNS characters with a dash. If the result | ||
// is not a valid DNS subdomain, returns `result, false`. Otherwise, returns the | ||
// `result, true`. | ||
func MetadataName(name string) (string, bool) { | ||
result := invalidNameChars.ReplaceAllString(name, "-") | ||
return result, validation.IsDNS1123Subdomain(result) == nil | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package k8sutil | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMetadataName(t *testing.T) { | ||
type testCase struct { | ||
name string | ||
in string | ||
expectedResult string | ||
expectedValid bool | ||
} | ||
for _, tc := range []testCase{ | ||
{ | ||
name: "empty", | ||
in: "", | ||
expectedResult: "", | ||
expectedValid: false, | ||
}, | ||
{ | ||
name: "invalid", | ||
in: "foo-bar.123!", | ||
expectedResult: "foo-bar.123-", | ||
expectedValid: false, | ||
}, | ||
{ | ||
name: "too long", | ||
in: fmt.Sprintf("foo-bar_%s", strings.Repeat("1234567890", 50)), | ||
expectedResult: fmt.Sprintf("foo-bar-%s", strings.Repeat("1234567890", 50)), | ||
expectedValid: false, | ||
}, | ||
{ | ||
name: "valid", | ||
in: "foo-bar.123", | ||
expectedResult: "foo-bar.123", | ||
expectedValid: true, | ||
}, | ||
{ | ||
name: "valid with underscore", | ||
in: "foo-bar_123", | ||
expectedResult: "foo-bar-123", | ||
expectedValid: true, | ||
}, | ||
{ | ||
name: "valid with colon", | ||
in: "foo-bar:123", | ||
expectedResult: "foo-bar-123", | ||
expectedValid: true, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
actualResult, actualValid := MetadataName(tc.in) | ||
assert.Equal(t, tc.expectedResult, actualResult) | ||
assert.Equal(t, tc.expectedValid, actualValid) | ||
}) | ||
} | ||
} |
This file contains 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
This file contains 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