diff --git a/pkg/registry/service/rest.go b/pkg/registry/service/rest.go index 3b524a2bc7f..70d573790e8 100644 --- a/pkg/registry/service/rest.go +++ b/pkg/registry/service/rest.go @@ -309,6 +309,15 @@ func (rs *REST) ResourceLocation(ctx api.Context, id string) (*url.URL, http.Rou Scheme: svcScheme, Host: net.JoinHostPort(ip, strconv.Itoa(port)), }, rs.proxyTransport, nil + } else { + port, err := strconv.ParseInt(portStr, 10, 64) + if err == nil && int(port) == ss.Ports[i].Port { + ip := ss.Addresses[rand.Intn(len(ss.Addresses))].IP + return &url.URL{ + Scheme: svcScheme, + Host: net.JoinHostPort(ip, portStr), + }, rs.proxyTransport, nil + } } } } diff --git a/pkg/registry/service/rest_test.go b/pkg/registry/service/rest_test.go index 3fe14916ee7..6e9ea4a5720 100644 --- a/pkg/registry/service/rest_test.go +++ b/pkg/registry/service/rest_test.go @@ -491,6 +491,18 @@ func TestServiceRegistryResourceLocation(t *testing.T) { t.Errorf("Expected %v, but got %v", e, a) } + // Test a name + port number. + location, _, err = redirector.ResourceLocation(ctx, "foo:93") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if location == nil { + t.Errorf("Unexpected nil: %v", location) + } + if e, a := "//1.2.3.4:93", location.String(); e != a { + t.Errorf("Expected %v, but got %v", e, a) + } + // Test a scheme + name + port. location, _, err = redirector.ResourceLocation(ctx, "https:foo:p") if err != nil {