Move port forward protocol constant to subpackage

Move port forward protocol name constant to a subpackage underneath
pkg/kubelet to avoid flags applicable to the kubelet leaking into
kubectl. Eventually, handlers for specific protocol versions will move
into the new subpackage as well.
This commit is contained in:
Andy Goldstein
2015-10-21 22:37:26 -04:00
parent ff9883d9ec
commit ad4f108bfa
3 changed files with 26 additions and 7 deletions

View File

@@ -29,7 +29,7 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/kubelet" "k8s.io/kubernetes/pkg/kubelet/portforward"
"k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/httpstream" "k8s.io/kubernetes/pkg/util/httpstream"
) )
@@ -129,7 +129,7 @@ func (pf *PortForwarder) ForwardPorts() error {
defer pf.Close() defer pf.Close()
var err error var err error
pf.streamConn, _, err = pf.dialer.Dial(kubelet.PortForwardProtocolV1Name) pf.streamConn, _, err = pf.dialer.Dial(portforward.PortForwardProtocolV1Name)
if err != nil { if err != nil {
return fmt.Errorf("error upgrading connection: %s", err) return fmt.Errorf("error upgrading connection: %s", err)
} }

View File

@@ -0,0 +1,21 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// package portforward contains server-side logic for handling port forwarding requests.
package portforward
// The subprotocol "portforward.k8s.io" is used for port forwarding.
const PortForwardProtocolV1Name = "portforward.k8s.io"

View File

@@ -48,6 +48,7 @@ import (
"k8s.io/kubernetes/pkg/healthz" "k8s.io/kubernetes/pkg/healthz"
"k8s.io/kubernetes/pkg/httplog" "k8s.io/kubernetes/pkg/httplog"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/portforward"
"k8s.io/kubernetes/pkg/types" "k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/flushwriter" "k8s.io/kubernetes/pkg/util/flushwriter"
@@ -781,17 +782,14 @@ func (s *Server) getPortForward(request *restful.Request, response *restful.Resp
ServePortForward(response.ResponseWriter, request.Request, s.host, podName, uid, s.host.StreamingConnectionIdleTimeout(), defaultStreamCreationTimeout) ServePortForward(response.ResponseWriter, request.Request, s.host, podName, uid, s.host.StreamingConnectionIdleTimeout(), defaultStreamCreationTimeout)
} }
// The subprotocol "portforward.k8s.io" is used for port forwarding.
const PortForwardProtocolV1Name = "portforward.k8s.io"
// ServePortForward handles a port forwarding request. A single request is // ServePortForward handles a port forwarding request. A single request is
// kept alive as long as the client is still alive and the connection has not // kept alive as long as the client is still alive and the connection has not
// been timed out due to idleness. This function handles multiple forwarded // been timed out due to idleness. This function handles multiple forwarded
// connections; i.e., multiple `curl http://localhost:8888/` requests will be // connections; i.e., multiple `curl http://localhost:8888/` requests will be
// handled by a single invocation of ServePortForward. // handled by a single invocation of ServePortForward.
func ServePortForward(w http.ResponseWriter, req *http.Request, portForwarder PortForwarder, podName string, uid types.UID, idleTimeout time.Duration, streamCreationTimeout time.Duration) { func ServePortForward(w http.ResponseWriter, req *http.Request, portForwarder PortForwarder, podName string, uid types.UID, idleTimeout time.Duration, streamCreationTimeout time.Duration) {
supportedPortForwardProtocols := []string{PortForwardProtocolV1Name} supportedPortForwardProtocols := []string{portforward.PortForwardProtocolV1Name}
_, err := httpstream.Handshake(req, w, supportedPortForwardProtocols, PortForwardProtocolV1Name) _, err := httpstream.Handshake(req, w, supportedPortForwardProtocols, portforward.PortForwardProtocolV1Name)
// negotiated protocol isn't currently used server side, but could be in the future // negotiated protocol isn't currently used server side, but could be in the future
if err != nil { if err != nil {
// Handshake writes the error to the client // Handshake writes the error to the client