Merge pull request #12919 from gmarek/use_api_ports

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot
2015-10-22 19:53:41 -07:00
16 changed files with 196 additions and 47 deletions

View File

@@ -31,6 +31,7 @@ import (
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/registry/generic"
nodeetcd "k8s.io/kubernetes/pkg/registry/node/etcd"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/fielderrors"
@@ -228,7 +229,14 @@ func ResourceLocation(getter ResourceGetter, rt http.RoundTripper, ctx api.Conte
// LogLocation returns the log URL for a pod container. If opts.Container is blank
// and only one container is present in the pod, that container is used.
func LogLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ctx api.Context, name string, opts *api.PodLogOptions) (*url.URL, http.RoundTripper, error) {
func LogLocation(
getter ResourceGetter,
connInfo client.ConnectionInfoGetter,
ctx api.Context,
name string,
opts *api.PodLogOptions,
hostLocator nodeetcd.HostLocator,
) (*url.URL, http.RoundTripper, error) {
pod, err := getPod(getter, ctx, name)
if err != nil {
return nil, nil, err
@@ -252,6 +260,13 @@ func LogLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ct
if err != nil {
return nil, nil, err
}
daemonPort, err := hostLocator.HostKubeletPort(pod, ctx)
if err != nil {
return nil, nil, err
}
if daemonPort > 0 {
nodePort = uint(daemonPort)
}
params := url.Values{}
if opts.Follow {
params.Add("follow", "true")
@@ -322,17 +337,40 @@ func streamParams(params url.Values, opts runtime.Object) error {
// AttachLocation returns the attach URL for a pod container. If opts.Container is blank
// and only one container is present in the pod, that container is used.
func AttachLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ctx api.Context, name string, opts *api.PodAttachOptions) (*url.URL, http.RoundTripper, error) {
return streamLocation(getter, connInfo, ctx, name, opts, opts.Container, "attach")
func AttachLocation(
getter ResourceGetter,
connInfo client.ConnectionInfoGetter,
ctx api.Context,
name string,
opts *api.PodAttachOptions,
hostLocator nodeetcd.HostLocator,
) (*url.URL, http.RoundTripper, error) {
return streamLocation(getter, connInfo, ctx, name, opts, opts.Container, "attach", hostLocator)
}
// ExecLocation returns the exec URL for a pod container. If opts.Container is blank
// and only one container is present in the pod, that container is used.
func ExecLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ctx api.Context, name string, opts *api.PodExecOptions) (*url.URL, http.RoundTripper, error) {
return streamLocation(getter, connInfo, ctx, name, opts, opts.Container, "exec")
func ExecLocation(
getter ResourceGetter,
connInfo client.ConnectionInfoGetter,
ctx api.Context,
name string,
opts *api.PodExecOptions,
hostLocator nodeetcd.HostLocator,
) (*url.URL, http.RoundTripper, error) {
return streamLocation(getter, connInfo, ctx, name, opts, opts.Container, "exec", hostLocator)
}
func streamLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ctx api.Context, name string, opts runtime.Object, container, path string) (*url.URL, http.RoundTripper, error) {
func streamLocation(
getter ResourceGetter,
connInfo client.ConnectionInfoGetter,
ctx api.Context,
name string,
opts runtime.Object,
container,
path string,
hostLocator nodeetcd.HostLocator,
) (*url.URL, http.RoundTripper, error) {
pod, err := getPod(getter, ctx, name)
if err != nil {
return nil, nil, err
@@ -355,6 +393,13 @@ func streamLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter,
if err != nil {
return nil, nil, err
}
daemonPort, err := hostLocator.HostKubeletPort(pod, ctx)
if err != nil {
return nil, nil, err
}
if daemonPort > 0 {
nodePort = uint(daemonPort)
}
params := url.Values{}
if err := streamParams(params, opts); err != nil {
return nil, nil, err
@@ -369,7 +414,13 @@ func streamLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter,
}
// PortForwardLocation returns the port-forward URL for a pod.
func PortForwardLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ctx api.Context, name string) (*url.URL, http.RoundTripper, error) {
func PortForwardLocation(
getter ResourceGetter,
connInfo client.ConnectionInfoGetter,
ctx api.Context,
name string,
hostLocator nodeetcd.HostLocator,
) (*url.URL, http.RoundTripper, error) {
pod, err := getPod(getter, ctx, name)
if err != nil {
return nil, nil, err
@@ -384,6 +435,13 @@ func PortForwardLocation(getter ResourceGetter, connInfo client.ConnectionInfoGe
if err != nil {
return nil, nil, err
}
daemonPort, err := hostLocator.HostKubeletPort(pod, ctx)
if err != nil {
return nil, nil, err
}
if daemonPort > 0 {
nodePort = uint(daemonPort)
}
loc := &url.URL{
Scheme: nodeScheme,
Host: fmt.Sprintf("%s:%d", nodeHost, nodePort),