Kubebuilder: Don't recommend using manager.GetClient in tests

Created on 15 Feb 2021  路  7Comments  路  Source: kubernetes-sigs/kubebuilder

Using the manager.GetClient() in tests is a bad idea and should not be recommended by the documentation. The manager's client is a cached client.Reader which is fine for a controller - but in tests you probably want a strongly consistent client.

This is the documentation i am referring to:
https://github.com/kubernetes-sigs/kubebuilder/blame/master/docs/book/src/cronjob-tutorial/testdata/project/controllers/suite_test.go#L115-L116

There's an older issue that explains the problem in more detail: https://github.com/kubernetes-sigs/controller-runtime/issues/343

I'd suggest updating the documentation about that. What do you think? Did anybody else run into that issue yet?

/kind bug
/kind documentation

good first issue help wanted kindocumentation triagaccepted

Most helpful comment

Hello @Adirio, I would like to contribute to the project by working on this issue :)

All 7 comments

Any help with the documentaiton is appreciated
/help
/good-first-issue

P.S.: the most relevant part of the linked conversation is https://github.com/kubernetes-sigs/controller-runtime/issues/343#issuecomment-469435686

@Adirio:
This request has been marked as suitable for new contributors.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-good-first-issue command.

In response to this:

Any help with the documentaiton is appreciated
/help
/good-first-issue

P.S.: the most relevant part of the linked conversation is https://github.com/kubernetes-sigs/controller-runtime/issues/343#issuecomment-469435686

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

/remove-kind bug

Hello @Adirio, I would like to contribute to the project by working on this issue :)

Sure, help is always apreciated. Feel free to submit a PR and assign me so that I can review it.

/assign

To be clear for posterity (because the follow-up PR broke the tests): You shouldn't use the manager's client in assertions in tests. You should use the manager's client in your reconciler.

Was this page helpful?
0 / 5 - 0 ratings