move port splitting to common place; add to node resource location

This commit is contained in:
Daniel Smith
2015-04-20 14:31:44 -07:00
parent 996ded35ff
commit 27ee6ea0de
5 changed files with 125 additions and 19 deletions

View File

@@ -23,7 +23,6 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
@@ -34,6 +33,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/endpoint"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/golang/glog"
@@ -206,15 +206,10 @@ var _ = rest.Redirector(&REST{})
// ResourceLocation returns a URL to which one can send traffic for the specified service.
func (rs *REST) ResourceLocation(ctx api.Context, id string) (*url.URL, http.RoundTripper, error) {
// Allow ID as "svcname" or "svcname:port".
parts := strings.Split(id, ":")
if len(parts) > 2 {
svcName, portStr, valid := util.SplitPort(id)
if !valid {
return nil, nil, errors.NewBadRequest(fmt.Sprintf("invalid service request %q", id))
}
svcName := parts[0]
portStr := ""
if len(parts) == 2 {
portStr = parts[1]
}
eps, err := rs.endpoints.GetEndpoints(ctx, svcName)
if err != nil {