Implement redirection & proxying for minions

This commit is contained in:
Daniel Smith 2014-10-17 14:21:53 -07:00
parent 82bbcee8d9
commit f748e2d2c5
3 changed files with 24 additions and 4 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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 {