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

@@ -21,7 +21,6 @@ import (
"net"
"net/http"
"net/url"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
@@ -31,6 +30,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
)
@@ -150,16 +150,11 @@ func getPod(getter ResourceGetter, ctx api.Context, name string) (*api.Pod, erro
func ResourceLocation(getter ResourceGetter, ctx api.Context, id string) (*url.URL, http.RoundTripper, error) {
// Allow ID as "podname" or "podname:port". If port is not specified,
// try to use the first defined port on the pod.
parts := strings.Split(id, ":")
if len(parts) > 2 {
name, port, valid := util.SplitPort(id)
if !valid {
return nil, nil, errors.NewBadRequest(fmt.Sprintf("invalid pod request %q", id))
}
name := parts[0]
port := ""
if len(parts) == 2 {
// TODO: if port is not a number but a "(container)/(portname)", do a name lookup.
port = parts[1]
}
// TODO: if port is not a number but a "(container)/(portname)", do a name lookup.
pod, err := getPod(getter, ctx, name)
if err != nil {