Skip to content

feature: add kubernetes api_client parameter to kubetest client - #144

Open
edaniszewski wants to merge 3 commits into
masterfrom
custom-client
Open

feature: add kubernetes api_client parameter to kubetest client#144
edaniszewski wants to merge 3 commits into
masterfrom
custom-client

Conversation

@edaniszewski

Copy link
Copy Markdown
Contributor

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:

@alexandrem

Copy link
Copy Markdown

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.

@edaniszewski

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants