Fix branch names support for k8s runtime (#2020)
* fix branch names support for k8s * remove logs Co-authored-by: Asim Aslam <asim@aslam.me>
This commit is contained in:
@@ -88,13 +88,16 @@ func CertsFromPEM(pemCerts []byte) ([]*x509.Certificate, error) {
|
||||
}
|
||||
|
||||
// Format is used to format a string value into a k8s valid name
|
||||
// https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
|
||||
func Format(v string) string {
|
||||
// to lower case
|
||||
v = strings.ToLower(v)
|
||||
// / to dashes
|
||||
v = strings.ReplaceAll(v, "/", "-")
|
||||
// dots to dashes
|
||||
v = strings.ReplaceAll(v, ".", "-")
|
||||
replaceChars := []string{"/", ".", "_"}
|
||||
for _, s := range replaceChars {
|
||||
v = strings.ReplaceAll(v, s, "-")
|
||||
}
|
||||
|
||||
// limit to 253 chars
|
||||
if len(v) > 253 {
|
||||
v = v[:253]
|
||||
|
@@ -36,6 +36,8 @@ func TestFormatName(t *testing.T) {
|
||||
{"foo.bar", "foo-bar"},
|
||||
{"Foo.Bar", "foo-bar"},
|
||||
{"go.micro.foo.bar", "go-micro-foo-bar"},
|
||||
{"go.micro.foo.bar", "go-micro-foo-bar"},
|
||||
{"foo/bar_baz", "foo-bar-baz"},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
Reference in New Issue
Block a user