kubetest icon indicating copy to clipboard operation
kubetest copied to clipboard

feature: add kubernetes api_client parameter to kubetest client

Open edaniszewski opened this issue 4 years ago • 2 comments

This PR:

  • allows tests to specify their own api_client parameter to pass to the Kubernetes client.
  • allows kubernetes objects to specify their own api_client

Caveats:

  • In order for the test client (e.g. returned by the kube fixture) to use a custom api_client, the test author must manually set it at the top of the test, e.g.

    def test_something(kube):
        kube.api_client = custom_client
    
        kube.load_deployment(...)
    
  • Interactions through the kube client will have access to the custom client and will use it if set, however if any of the kubetest object wrappers (e.g. kubetest.objects.deployment.Deployment) are initialized manually:

    d = Deployment(obj)
    

    then they will not have access to the custom client because there is no direct link to the currently active test client. it could be added in the future, but that requires a hard look at the design and any implications it would have, particularly if tests are run in parallel. For now, if its required that an object is initialized directly, the api_client can be passed directly to it

    d = Deployment(obj, client=custom_client)
    

Related:

  • #133

edaniszewski avatar Sep 27 '19 19:09 edaniszewski

To my knowledge we have to patch everything under kubetest.objects as well that is currently using the global apiclient.

For instance Node.refresh() and many others.

I'm currently monkeypatching a lot of those in my tests.

alexandrem avatar Sep 27 '19 19:09 alexandrem

Good point. I've updated so that all api objects which the TestClient creates get the api_client defined for the test client.

I'm not totally convinced this implementation is great largely because there are a few api objects (role bindings, cluster role bindings) which are set up via markers and are done before the test starts, so there isn't a good way of sharing the client with them.

edaniszewski avatar Sep 27 '19 19:09 edaniszewski