From e69475d29e7b305fda18a56e72c9d22631c15a6f Mon Sep 17 00:00:00 2001 From: "Madhusudan.C.S" Date: Sat, 29 Oct 2016 18:25:02 -0700 Subject: [PATCH] Make the fake command factory return the clientset with appropriate rest clients for all the API groups. Calling `internalclientset.New()` with a rest client as an argument simply copies that rest client to all the API group clients irrespective of the configured GroupVersion or versionedAPIPath in the client. So only one API group client gets the client configured correctly for that API group. All the other API group clients get misconfigured rest clients. On the other hand, `internalclientset.NewForConfigOrDie()` does the right thing by reconfiguring the passed configs for each API group and initializes an appropriate rest client for that group. Now that we are relying on the `NewForConfigOrDie()` method to initialize the rest clients, we need to swap the underlying http clients in each of these rest clients with a fake one for testing. --- pkg/kubectl/cmd/testing/fake.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/kubectl/cmd/testing/fake.go b/pkg/kubectl/cmd/testing/fake.go index ae3256c8ee5..b07db0ec95f 100644 --- a/pkg/kubectl/cmd/testing/fake.go +++ b/pkg/kubectl/cmd/testing/fake.go @@ -413,14 +413,23 @@ func (f *fakeAPIFactory) JSONEncoder() runtime.Encoder { } func (f *fakeAPIFactory) ClientSet() (*internalclientset.Clientset, error) { - // Swap out the HTTP client out of the client with the fake's version. + // Swap the HTTP client out of the REST client with the fake + // version. fakeClient := f.tf.Client.(*fake.RESTClient) - restClient, err := restclient.RESTClientFor(f.tf.ClientConfig) - if err != nil { - panic(err) - } - restClient.Client = fakeClient.Client - return internalclientset.New(restClient), f.tf.Err + clientset := internalclientset.NewForConfigOrDie(f.tf.ClientConfig) + clientset.CoreClient.RESTClient.Client = fakeClient.Client + clientset.AuthenticationClient.RESTClient.Client = fakeClient.Client + clientset.AuthorizationClient.RESTClient.Client = fakeClient.Client + clientset.AutoscalingClient.RESTClient.Client = fakeClient.Client + clientset.BatchClient.RESTClient.Client = fakeClient.Client + clientset.CertificatesClient.RESTClient.Client = fakeClient.Client + clientset.ExtensionsClient.RESTClient.Client = fakeClient.Client + clientset.RbacClient.RESTClient.Client = fakeClient.Client + clientset.StorageClient.RESTClient.Client = fakeClient.Client + clientset.AppsClient.RESTClient.Client = fakeClient.Client + clientset.PolicyClient.RESTClient.Client = fakeClient.Client + clientset.DiscoveryClient.RESTClient.Client = fakeClient.Client + return clientset, f.tf.Err } func (f *fakeAPIFactory) RESTClient() (*restclient.RESTClient, error) {