Refactor exec to make attach useful without a client.Config

The current executor structure is too dependent on client.Request
and client.Config. In order to do an attach from the server, it needs
to be possible to create an Executor from crypto/tls#TLSConfig and to
bypassing having a client.Request.

Changes:

* remotecommand.spdyExecutor - handles upgrading a request to SPDY and getting a connection
* remotecommand.NewAttach / New - moved to exec / portforward / attach since they handle requests
* Remove request.Upgrade() - it's too coupled to SPDY, and can live with the spdyExecutor
* Add request.VersionedParams(runtime.Object, runtime.ObjectConvertor) to handle object -> query transform
This commit is contained in:
Clayton Coleman
2015-09-26 20:00:39 -04:00
parent 2f90f660c1
commit 3f1b18fbba
13 changed files with 331 additions and 306 deletions

View File

@@ -19,6 +19,7 @@ package cmd
import (
"fmt"
"net/http"
"net/url"
"testing"
"github.com/spf13/cobra"
@@ -30,12 +31,14 @@ import (
)
type fakePortForwarder struct {
req *client.Request
pfErr error
method string
url *url.URL
pfErr error
}
func (f *fakePortForwarder) ForwardPorts(req *client.Request, config *client.Config, ports []string, stopChan <-chan struct{}) error {
f.req = req
func (f *fakePortForwarder) ForwardPorts(method string, url *url.URL, config *client.Config, ports []string, stopChan <-chan struct{}) error {
f.method = method
f.url = url
return f.pfErr
}
@@ -92,12 +95,20 @@ func TestPortForward(t *testing.T) {
if test.pfErr && err != ff.pfErr {
t.Errorf("%s: Unexpected exec error: %v", test.name, err)
}
if !test.pfErr && ff.req.URL().Path != test.pfPath {
t.Errorf("%s: Did not get expected path for portforward request", test.name)
}
if !test.pfErr && err != nil {
t.Errorf("%s: Unexpected error: %v", test.name, err)
}
if test.pfErr {
continue
}
if ff.url.Path != test.pfPath {
t.Errorf("%s: Did not get expected path for portforward request", test.name)
}
if ff.method != "POST" {
t.Errorf("%s: Did not get method for attach request: %s", test.name, ff.method)
}
}
}
@@ -154,7 +165,7 @@ func TestPortForwardWithPFlag(t *testing.T) {
if test.pfErr && err != ff.pfErr {
t.Errorf("%s: Unexpected exec error: %v", test.name, err)
}
if !test.pfErr && ff.req.URL().Path != test.pfPath {
if !test.pfErr && ff.url.Path != test.pfPath {
t.Errorf("%s: Did not get expected path for portforward request", test.name)
}
if !test.pfErr && err != nil {