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:
@@ -211,7 +211,6 @@ func (k *kubernetes) getService(labels map[string]string, opts ...client.GetOpti
|
|||||||
|
|
||||||
// now try get a deeper status
|
// now try get a deeper status
|
||||||
state := item.Status.Containers[0].State
|
state := item.Status.Containers[0].State
|
||||||
|
|
||||||
// set start time
|
// set start time
|
||||||
if state.Running != nil {
|
if state.Running != nil {
|
||||||
svc.Metadata["started"] = state.Running.Started
|
svc.Metadata["started"] = state.Running.Started
|
||||||
@@ -484,7 +483,7 @@ func (k *kubernetes) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error
|
|||||||
|
|
||||||
// add version to labels if a version has been supplied
|
// add version to labels if a version has been supplied
|
||||||
if len(options.Version) > 0 {
|
if len(options.Version) > 0 {
|
||||||
labels["version"] = options.Version
|
labels["version"] = client.Format(options.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(options.Type) > 0 {
|
if len(options.Type) > 0 {
|
||||||
@@ -521,7 +520,7 @@ func (k *kubernetes) Update(s *runtime.Service, opts ...runtime.UpdateOption) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(s.Version) > 0 {
|
if len(s.Version) > 0 {
|
||||||
labels["version"] = s.Version
|
labels["version"] = client.Format(s.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the existing service
|
// get the existing service
|
||||||
|
@@ -88,13 +88,16 @@ func CertsFromPEM(pemCerts []byte) ([]*x509.Certificate, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Format is used to format a string value into a k8s valid name
|
// 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 {
|
func Format(v string) string {
|
||||||
// to lower case
|
// to lower case
|
||||||
v = strings.ToLower(v)
|
v = strings.ToLower(v)
|
||||||
// / to dashes
|
// / to dashes
|
||||||
v = strings.ReplaceAll(v, "/", "-")
|
replaceChars := []string{"/", ".", "_"}
|
||||||
// dots to dashes
|
for _, s := range replaceChars {
|
||||||
v = strings.ReplaceAll(v, ".", "-")
|
v = strings.ReplaceAll(v, s, "-")
|
||||||
|
}
|
||||||
|
|
||||||
// limit to 253 chars
|
// limit to 253 chars
|
||||||
if len(v) > 253 {
|
if len(v) > 253 {
|
||||||
v = v[:253]
|
v = v[:253]
|
||||||
|
@@ -36,6 +36,8 @@ func TestFormatName(t *testing.T) {
|
|||||||
{"foo.bar", "foo-bar"},
|
{"foo.bar", "foo-bar"},
|
||||||
{"Foo.Bar", "foo-bar"},
|
{"Foo.Bar", "foo-bar"},
|
||||||
{"go.micro.foo.bar", "go-micro-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 {
|
for _, test := range testCases {
|
||||||
|
Reference in New Issue
Block a user