diff --git a/pkg/registry/minion/rest.go b/pkg/registry/minion/rest.go index 9c6e177a7a5..68f63365af9 100644 --- a/pkg/registry/minion/rest.go +++ b/pkg/registry/minion/rest.go @@ -17,11 +17,15 @@ limitations under the License. package minion import ( + "errors" "fmt" + "net" + "strconv" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -38,8 +42,8 @@ func NewREST(m Registry) *REST { } } -var ErrDoesNotExist = fmt.Errorf("The requested resource does not exist.") -var ErrNotHealty = fmt.Errorf("The requested minion is not healthy.") +var ErrDoesNotExist = errors.New("The requested resource does not exist.") +var ErrNotHealty = errors.New("The requested minion is not healthy.") func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) { minion, ok := obj.(*api.Minion) @@ -104,3 +108,17 @@ func (rs *REST) Update(ctx api.Context, minion runtime.Object) (<-chan runtime.O func (rs *REST) toApiMinion(name string) *api.Minion { return &api.Minion{TypeMeta: api.TypeMeta{ID: name}} } + +// ResourceLocation returns a URL to which one can send traffic for the specified minion. +func (rs *REST) ResourceLocation(ctx api.Context, id string) (string, error) { + minion, err := rs.registry.GetMinion(ctx, id) + if err != nil { + return "", err + } + host := minion.HostIP + if host == "" { + host = minion.ID + } + // TODO: Minion webservers should be secure! + return "http://" + net.JoinHostPort(host, strconv.Itoa(ports.KubeletPort)), nil +} diff --git a/pkg/registry/service/rest.go b/pkg/registry/service/rest.go index 42f26810d53..dce10514825 100644 --- a/pkg/registry/service/rest.go +++ b/pkg/registry/service/rest.go @@ -245,7 +245,9 @@ func (rs *REST) ResourceLocation(ctx api.Context, id string) (string, error) { if len(e.Endpoints) == 0 { return "", fmt.Errorf("no endpoints available for %v", id) } - return "http://" + e.Endpoints[rand.Intn(len(e.Endpoints))], nil + // We leave off the scheme ('http://') because we have no idea what sort of server + // is listening at this endpoint. + return e.Endpoints[rand.Intn(len(e.Endpoints))], nil } func (rs *REST) deleteExternalLoadBalancer(service *api.Service) error { diff --git a/pkg/registry/service/rest_test.go b/pkg/registry/service/rest_test.go index 5907146b016..fb99ad384c3 100644 --- a/pkg/registry/service/rest_test.go +++ b/pkg/registry/service/rest_test.go @@ -360,7 +360,7 @@ func TestServiceRegistryResourceLocation(t *testing.T) { if err != nil { t.Errorf("Unexpected error: %v", err) } - if e, a := "http://foo:80", location; e != a { + if e, a := "foo:80", location; e != a { t.Errorf("Expected %v, but got %v", e, a) } if e, a := "foo", registry.GottenID; e != a {