Skip to content

Commit

Permalink
Fix dropped namespace in url parsing (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
leth authored and bboreham committed Nov 9, 2018
1 parent e017e7c commit ab6d3db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions httpgrpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ func ParseURL(unparsed string) (string, []grpc.DialOption, error) {
if err != nil {
return "", nil, err
}
parts := strings.SplitN(host, ".", 2)
service, namespace := parts[0], "default"
if len(parts) == 2 {
parts := strings.SplitN(host, ".", 3)
service, namespace, domain := parts[0], "default", ""
if len(parts) > 1 {
namespace = parts[1]
domain = "." + namespace
}
if len(parts) > 2 {
domain = domain + "." + parts[2]
}
balancer := kuberesolver.NewWithNamespace(namespace)
address := fmt.Sprintf("kubernetes://%s:%s", service, port)
address := fmt.Sprintf("kubernetes://%s%s:%s", service, domain, port)
dialOptions := []grpc.DialOption{balancer.DialOption()}
return address, dialOptions, nil

Expand Down
3 changes: 2 additions & 1 deletion httpgrpc/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func TestParseURL(t *testing.T) {
}{
{"direct://foo", "foo", nil},
{"kubernetes://foo:123", "kubernetes://foo:123", nil},
{"querier.cortex:995", "kubernetes://querier:995", nil},
{"querier.cortex:995", "kubernetes://querier.cortex:995", nil},
{"foo.bar.svc.local:995", "kubernetes://foo.bar.svc.local:995", nil},
} {
got, _, err := ParseURL(tc.input)
if !reflect.DeepEqual(tc.err, err) {
Expand Down

0 comments on commit ab6d3db

Please sign in to comment.