Skip to content

Commit

Permalink
Merge pull request kubernetes#19105 from smarterclayton/prepare_negot…
Browse files Browse the repository at this point in the history
…iate

Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Jan 27, 2016
2 parents a95f1b8 + 38c7ede commit 458eb52
Show file tree
Hide file tree
Showing 41 changed files with 306 additions and 231 deletions.
4 changes: 2 additions & 2 deletions cluster/addons/dns/kube2sky/kube2sky.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ func newKubeClient() (*kclient.Client, error) {
if masterURL != "" && *argKubecfgFile == "" {
// Only --kube-master-url was provided.
config = &kclient.Config{
Host: masterURL,
GroupVersion: &unversioned.GroupVersion{Version: "v1"},
Host: masterURL,
ContentConfig: kclient.ContentConfig{GroupVersion: &unversioned.GroupVersion{Version: "v1"}},
}
} else {
// We either have:
Expand Down
8 changes: 4 additions & 4 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
glog.Fatalf("Failed to connect to etcd")
}

cl := client.NewOrDie(&client.Config{Host: apiServer.URL, GroupVersion: testapi.Default.GroupVersion()})
cl := client.NewOrDie(&client.Config{Host: apiServer.URL, ContentConfig: client.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})

// TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
cl.ExtensionsClient = client.NewExtensionsOrDie(&client.Config{Host: apiServer.URL, GroupVersion: testapi.Extensions.GroupVersion()})
cl.ExtensionsClient = client.NewExtensionsOrDie(&client.Config{Host: apiServer.URL, ContentConfig: client.ContentConfig{GroupVersion: testapi.Extensions.GroupVersion()}})

// Master
host, port, err := net.SplitHostPort(strings.TrimLeft(apiServer.URL, "http://"))
Expand Down Expand Up @@ -984,10 +984,10 @@ func main() {
// Wait for the synchronization threads to come up.
time.Sleep(time.Second * 10)

kubeClient := client.NewOrDie(&client.Config{Host: apiServerURL, GroupVersion: testapi.Default.GroupVersion()})
kubeClient := client.NewOrDie(&client.Config{Host: apiServerURL, ContentConfig: client.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})
// TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
kubeClient.ExtensionsClient = client.NewExtensionsOrDie(&client.Config{Host: apiServerURL, GroupVersion: testapi.Extensions.GroupVersion()})
kubeClient.ExtensionsClient = client.NewExtensionsOrDie(&client.Config{Host: apiServerURL, ContentConfig: client.ContentConfig{GroupVersion: testapi.Extensions.GroupVersion()}})

// Run tests in parallel
testFuncs := []testFunc{
Expand Down
4 changes: 2 additions & 2 deletions contrib/mesos/pkg/scheduler/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ func newLifecycleTest(t *testing.T) lifecycleTest {

// create framework
client := client.NewOrDie(&client.Config{
Host: apiServer.server.URL,
GroupVersion: testapi.Default.GroupVersion(),
Host: apiServer.server.URL,
ContentConfig: client.ContentConfig{GroupVersion: testapi.Default.GroupVersion()},
})
c := *schedcfg.CreateDefaultConfig()
fw := framework.New(framework.Config{
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/testapi/testapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func init() {
Extensions = Groups[extensions.GroupName]
}

func (g TestGroup) ContentConfig() (string, *unversioned.GroupVersion, runtime.Codec) {
return "application/json", g.GroupVersion(), g.Codec()
}

func (g TestGroup) GroupVersion() *unversioned.GroupVersion {
copyOfGroupVersion := g.externalGroupVersion
return &copyOfGroupVersion
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/cache/listwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestListWatchesCanList(t *testing.T) {
server := httptest.NewServer(&handler)
// TODO: Uncomment when fix #19254
// defer server.Close()
client := client.NewOrDie(&client.Config{Host: server.URL, GroupVersion: testapi.Default.GroupVersion()})
client := client.NewOrDie(&client.Config{Host: server.URL, ContentConfig: client.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})
lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector)
// This test merely tests that the correct request is made.
lw.List(api.ListOptions{})
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestListWatchesCanWatch(t *testing.T) {
server := httptest.NewServer(&handler)
// TODO: Uncomment when fix #19254
// defer server.Close()
client := client.NewOrDie(&client.Config{Host: server.URL, GroupVersion: testapi.Default.GroupVersion()})
client := client.NewOrDie(&client.Config{Host: server.URL, ContentConfig: client.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})
lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector)
// This test merely tests that the correct request is made.
lw.Watch(api.ListOptions{ResourceVersion: item.rv})
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/unversioned/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *RESTClient) Delete() *unversioned.Request {
}

func (c *RESTClient) request(verb string) *unversioned.Request {
return unversioned.NewRequest(c, verb, &url.URL{Host: "localhost"}, "", *testapi.Default.GroupVersion(), c.Codec, nil)
return unversioned.NewRequest(c, verb, &url.URL{Host: "localhost"}, "", unversioned.ContentConfig{GroupVersion: testapi.Default.GroupVersion(), Codec: c.Codec}, nil)
}

func (c *RESTClient) Do(req *http.Request) (*http.Response, error) {
Expand Down
52 changes: 38 additions & 14 deletions pkg/client/unversioned/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ type Config struct {
Host string
// APIPath is a sub-path that points to an API root.
APIPath string
// GroupVersion is the API version to talk to. Must be provided when initializing
// a RESTClient directly. When initializing a Client, will be set with the default
// code version.
GroupVersion *unversioned.GroupVersion
// Codec specifies the encoding and decoding behavior for runtime.Objects passed
// to a RESTClient or Client. Required when initializing a RESTClient, optional
// when initializing a Client.
Codec runtime.Codec
// Prefix is the sub path of the server. If not specified, the client will set
// a default value. Use "/" to indicate the server root should be used
Prefix string

// ContentConfig contains settings that affect how objects are transformed when
// sent to the server.
ContentConfig

// Server requires Basic authentication
Username string
Expand Down Expand Up @@ -120,6 +119,22 @@ type TLSClientConfig struct {
CAData []byte
}

type ContentConfig struct {
// ContentType specifies the wire format used to communicate with the server.
// This value will be set as the Accept header on requests made to the server, and
// as the default content type on any object sent to the server. If not set,
// "application/json" is used.
ContentType string
// GroupVersion is the API version to talk to. Must be provided when initializing
// a RESTClient directly. When initializing a Client, will be set with the default
// code version.
GroupVersion *unversioned.GroupVersion
// Codec specifies the encoding and decoding behavior for runtime.Objects passed
// to a RESTClient or Client. Required when initializing a RESTClient, optional
// when initializing a Client.
Codec runtime.Codec
}

// New creates a Kubernetes client for the given config. This client works with pods,
// replication controllers, daemons, and services. It allows operations such as list, get, update
// and delete on these objects. An error is returned if the provided configuration
Expand Down Expand Up @@ -407,16 +422,18 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
return nil, err
}

client := NewRESTClient(baseURL, versionedAPIPath, *config.GroupVersion, config.Codec, config.QPS, config.Burst)

transport, err := TransportFor(config)
if err != nil {
return nil, err
}

var httpClient *http.Client
if transport != http.DefaultTransport {
client.Client = &http.Client{Transport: transport}
httpClient = &http.Client{Transport: transport}
}

client := NewRESTClient(baseURL, versionedAPIPath, config.ContentConfig, config.QPS, config.Burst, httpClient)

return client, nil
}

Expand All @@ -432,16 +449,23 @@ func UnversionedRESTClientFor(config *Config) (*RESTClient, error) {
return nil, err
}

client := NewRESTClient(baseURL, versionedAPIPath, unversioned.SchemeGroupVersion, config.Codec, config.QPS, config.Burst)

transport, err := TransportFor(config)
if err != nil {
return nil, err
}

var httpClient *http.Client
if transport != http.DefaultTransport {
client.Client = &http.Client{Transport: transport}
httpClient = &http.Client{Transport: transport}
}

versionConfig := config.ContentConfig
if versionConfig.GroupVersion == nil {
v := unversioned.SchemeGroupVersion
versionConfig.GroupVersion = &v
}

client := NewRESTClient(baseURL, versionedAPIPath, versionConfig, config.QPS, config.Burst, httpClient)
return client, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/client/unversioned/helper_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ func TestNegotiateVersion(t *testing.T) {
},
{
name: "explicit version supported",
config: &unversioned.Config{GroupVersion: testapi.Default.GroupVersion()},
config: &unversioned.Config{ContentConfig: unversioned.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}},
serverVersions: []string{"/version1", testapi.Default.GroupVersion().String()},
clientVersions: []uapi.GroupVersion{{Version: "version1"}, *testapi.Default.GroupVersion()},
expectedVersion: testapi.Default.GroupVersion(),
},
{
name: "explicit version not supported",
config: &unversioned.Config{GroupVersion: testapi.Default.GroupVersion()},
config: &unversioned.Config{ContentConfig: unversioned.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}},
serverVersions: []string{"version1"},
clientVersions: []uapi.GroupVersion{{Version: "version1"}, *testapi.Default.GroupVersion()},
expectErr: func(err error) bool { return strings.Contains(err.Error(), `server does not support API version "v1"`) },
},
{
name: "connection refused error",
config: &unversioned.Config{GroupVersion: testapi.Default.GroupVersion()},
config: &unversioned.Config{ContentConfig: unversioned.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}},
serverVersions: []string{"version1"},
clientVersions: []uapi.GroupVersion{{Version: "version1"}, *testapi.Default.GroupVersion()},
sendErr: errors.New("connection refused"),
Expand Down
24 changes: 13 additions & 11 deletions pkg/client/unversioned/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ func TestSetKubernetesDefaults(t *testing.T) {
{
Config{},
Config{
APIPath: "/api",
GroupVersion: testapi.Default.GroupVersion(),
Codec: testapi.Default.Codec(),
QPS: 5,
Burst: 10,
APIPath: "/api",
ContentConfig: ContentConfig{
GroupVersion: testapi.Default.GroupVersion(),
Codec: testapi.Default.Codec(),
},
QPS: 5,
Burst: 10,
},
false,
},
Expand Down Expand Up @@ -188,7 +190,7 @@ func TestHelperGetServerAPIVersions(t *testing.T) {
}))
// TODO: Uncomment when fix #19254
// defer server.Close()
got, err := ServerAPIVersions(&Config{Host: server.URL, GroupVersion: &unversioned.GroupVersion{Group: "invalid version", Version: "one"}, Codec: testapi.Default.Codec()})
got, err := ServerAPIVersions(&Config{Host: server.URL, ContentConfig: ContentConfig{GroupVersion: &unversioned.GroupVersion{Group: "invalid version", Version: "one"}, Codec: testapi.Default.Codec()}})
if err != nil {
t.Fatalf("unexpected encoding error: %v", err)
}
Expand All @@ -208,7 +210,7 @@ func TestSetsCodec(t *testing.T) {
// "invalidVersion": {true, "", nil},
}
for version, expected := range testCases {
client, err := New(&Config{Host: "127.0.0.1", GroupVersion: &unversioned.GroupVersion{Version: version}})
client, err := New(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: &unversioned.GroupVersion{Version: version}}})
switch {
case err == nil && expected.Err:
t.Errorf("expected error but was nil")
Expand All @@ -222,20 +224,20 @@ func TestSetsCodec(t *testing.T) {
if e, a := expected.Prefix, client.RESTClient.versionedAPIPath; e != a {
t.Errorf("expected %#v, got %#v", e, a)
}
if e, a := expected.Codec, client.RESTClient.Codec; !reflect.DeepEqual(e, a) {
if e, a := expected.Codec, client.RESTClient.contentConfig.Codec; !reflect.DeepEqual(e, a) {
t.Errorf("expected %#v, got %#v", e, a)
}
}
}

func TestRESTClientRequires(t *testing.T) {
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", Codec: testapi.Default.Codec()}); err == nil {
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{Codec: testapi.Default.Codec()}}); err == nil {
t.Errorf("unexpected non-error")
}
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", GroupVersion: testapi.Default.GroupVersion()}); err == nil {
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}); err == nil {
t.Errorf("unexpected non-error")
}
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", GroupVersion: testapi.Default.GroupVersion(), Codec: testapi.Default.Codec()}); err != nil {
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: testapi.Default.GroupVersion(), Codec: testapi.Default.Codec()}}); err != nil {
t.Errorf("unexpected error: %v", err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/unversioned/remotecommand/remotecommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestRequestExecuteRemoteCommand(t *testing.T) {
server := httptest.NewServer(fakeExecServer(t, i, testCase.Stdin, testCase.Stdout, testCase.Stderr, testCase.Error, testCase.Tty, testCase.MessageCount))

url, _ := url.ParseRequestURI(server.URL)
c := client.NewRESTClient(url, "", unversioned.GroupVersion{Group: "x"}, nil, -1, -1)
c := client.NewRESTClient(url, "", client.ContentConfig{GroupVersion: &unversioned.GroupVersion{Group: "x"}}, -1, -1, nil)
req := c.Post().Resource("testing")
req.SetHeader(httpstream.HeaderProtocolVersion, StreamProtocolV2Name)
req.Param("command", "ls")
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestRequestAttachRemoteCommand(t *testing.T) {
server := httptest.NewServer(fakeExecServer(t, i, testCase.Stdin, testCase.Stdout, testCase.Stderr, testCase.Error, testCase.Tty, 1))

url, _ := url.ParseRequestURI(server.URL)
c := client.NewRESTClient(url, "", unversioned.GroupVersion{Group: "x"}, nil, -1, -1)
c := client.NewRESTClient(url, "", client.ContentConfig{GroupVersion: &unversioned.GroupVersion{Group: "x"}}, -1, -1, nil)
req := c.Post().Resource("testing")

conf := &client.Config{
Expand Down
Loading

0 comments on commit 458eb52

Please sign in to comment.