From 78412163034182421fa5be8e15aef96873f47f3b Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Fri, 17 Nov 2017 15:47:46 -0500 Subject: [PATCH] Allow constructing spdy executor from existing transports Kubernetes-commit: f82b1ba90ecfff0eb5731ba4da0b6f8acf79d3ff --- tools/remotecommand/BUILD | 1 - tools/remotecommand/remotecommand.go | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/remotecommand/BUILD b/tools/remotecommand/BUILD index b5b9adef..e665af3f 100644 --- a/tools/remotecommand/BUILD +++ b/tools/remotecommand/BUILD @@ -42,7 +42,6 @@ go_library( "//vendor/k8s.io/apimachinery/pkg/util/remotecommand:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library", - "//vendor/k8s.io/client-go/transport:go_default_library", "//vendor/k8s.io/client-go/transport/spdy:go_default_library", "//vendor/k8s.io/client-go/util/exec:go_default_library", ], diff --git a/tools/remotecommand/remotecommand.go b/tools/remotecommand/remotecommand.go index bcbe9fcd..6b69f366 100644 --- a/tools/remotecommand/remotecommand.go +++ b/tools/remotecommand/remotecommand.go @@ -27,7 +27,6 @@ import ( "k8s.io/apimachinery/pkg/util/httpstream" "k8s.io/apimachinery/pkg/util/remotecommand" restclient "k8s.io/client-go/rest" - "k8s.io/client-go/transport" spdy "k8s.io/client-go/transport/spdy" ) @@ -72,8 +71,18 @@ type streamExecutor struct { // NewSPDYExecutor connects to the provided server and upgrades the connection to // multiplexed bidirectional streams. func NewSPDYExecutor(config *restclient.Config, method string, url *url.URL) (Executor, error) { + wrapper, upgradeRoundTripper, err := spdy.RoundTripperFor(config) + if err != nil { + return nil, err + } + return NewSPDYExecutorForTransports(wrapper, upgradeRoundTripper, method, url) +} + +// NewSPDYExecutorForTransports connects to the provided server using the given transport, +// upgrades the response using the given upgrader to multiplexed bidirectional streams. +func NewSPDYExecutorForTransports(transport http.RoundTripper, upgrader spdy.Upgrader, method string, url *url.URL) (Executor, error) { return NewSPDYExecutorForProtocols( - config, method, url, + transport, upgrader, method, url, remotecommand.StreamProtocolV4Name, remotecommand.StreamProtocolV3Name, remotecommand.StreamProtocolV2Name, @@ -83,16 +92,11 @@ func NewSPDYExecutor(config *restclient.Config, method string, url *url.URL) (Ex // NewSPDYExecutorForProtocols connects to the provided server and upgrades the connection to // multiplexed bidirectional streams using only the provided protocols. Exposed for testing, most -// callers should use NewSPDYExecutor. -func NewSPDYExecutorForProtocols(config *restclient.Config, method string, url *url.URL, protocols ...string) (Executor, error) { - wrapper, upgradeRoundTripper, err := spdy.RoundTripperFor(config) - if err != nil { - return nil, err - } - wrapper = transport.DebugWrappers(wrapper) +// callers should use NewSPDYExecutor or NewSPDYExecutorForTransports. +func NewSPDYExecutorForProtocols(transport http.RoundTripper, upgrader spdy.Upgrader, method string, url *url.URL, protocols ...string) (Executor, error) { return &streamExecutor{ - upgrader: upgradeRoundTripper, - transport: wrapper, + upgrader: upgrader, + transport: transport, method: method, url: url, protocols: protocols,