mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
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.
This commit is contained in:
parent
7760c2f5fa
commit
e69475d29e
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user