mirror of https://github.com/k3s-io/k3s
Allow constructing spdy executor from existing transports
parent
56e62b684e
commit
f82b1ba90e
|
@ -256,7 +256,12 @@ func TestStream(t *testing.T) {
|
||||||
conf := &restclient.Config{
|
conf := &restclient.Config{
|
||||||
Host: server.URL,
|
Host: server.URL,
|
||||||
}
|
}
|
||||||
e, err := remoteclient.NewSPDYExecutorForProtocols(conf, "POST", req.URL(), testCase.ClientProtocols...)
|
transport, upgradeTransport, err := spdy.RoundTripperFor(conf)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%s: unexpected error: %v", name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
e, err := remoteclient.NewSPDYExecutorForProtocols(transport, upgradeTransport, "POST", req.URL(), testCase.ClientProtocols...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s: unexpected error: %v", name, err)
|
t.Errorf("%s: unexpected error: %v", name, err)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -42,7 +42,6 @@ go_library(
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/remotecommand:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/remotecommand:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/runtime: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/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/transport/spdy:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/util/exec:go_default_library",
|
"//vendor/k8s.io/client-go/util/exec:go_default_library",
|
||||||
],
|
],
|
||||||
|
|
|
@ -27,7 +27,6 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/util/httpstream"
|
"k8s.io/apimachinery/pkg/util/httpstream"
|
||||||
"k8s.io/apimachinery/pkg/util/remotecommand"
|
"k8s.io/apimachinery/pkg/util/remotecommand"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/transport"
|
|
||||||
spdy "k8s.io/client-go/transport/spdy"
|
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
|
// NewSPDYExecutor connects to the provided server and upgrades the connection to
|
||||||
// multiplexed bidirectional streams.
|
// multiplexed bidirectional streams.
|
||||||
func NewSPDYExecutor(config *restclient.Config, method string, url *url.URL) (Executor, error) {
|
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(
|
return NewSPDYExecutorForProtocols(
|
||||||
config, method, url,
|
transport, upgrader, method, url,
|
||||||
remotecommand.StreamProtocolV4Name,
|
remotecommand.StreamProtocolV4Name,
|
||||||
remotecommand.StreamProtocolV3Name,
|
remotecommand.StreamProtocolV3Name,
|
||||||
remotecommand.StreamProtocolV2Name,
|
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
|
// NewSPDYExecutorForProtocols connects to the provided server and upgrades the connection to
|
||||||
// multiplexed bidirectional streams using only the provided protocols. Exposed for testing, most
|
// multiplexed bidirectional streams using only the provided protocols. Exposed for testing, most
|
||||||
// callers should use NewSPDYExecutor.
|
// callers should use NewSPDYExecutor or NewSPDYExecutorForTransports.
|
||||||
func NewSPDYExecutorForProtocols(config *restclient.Config, method string, url *url.URL, protocols ...string) (Executor, error) {
|
func NewSPDYExecutorForProtocols(transport http.RoundTripper, upgrader spdy.Upgrader, 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)
|
|
||||||
return &streamExecutor{
|
return &streamExecutor{
|
||||||
upgrader: upgradeRoundTripper,
|
upgrader: upgrader,
|
||||||
transport: wrapper,
|
transport: transport,
|
||||||
method: method,
|
method: method,
|
||||||
url: url,
|
url: url,
|
||||||
protocols: protocols,
|
protocols: protocols,
|
||||||
|
|
Loading…
Reference in New Issue