Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reactor features in fake client #72

Closed
grantr opened this issue Jul 6, 2018 · 14 comments
Closed

Support reactor features in fake client #72

grantr opened this issue Jul 6, 2018 · 14 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@grantr
Copy link
Contributor

grantr commented Jul 6, 2018

Reactors are a useful feature of the official client's fake implementation. They allow injecting errors, simulating the actions of other controllers, and tracking the actions of the controller under test instead of just the output. IIUC, none of those are possible with the current fake client.

@droot
Copy link
Contributor

droot commented Jul 17, 2018

@fanzhangio Can you investigate how hard it will be to add reactors ?

@droot
Copy link
Contributor

droot commented Jul 27, 2018

@grantr Have you considered using https://github.com/golang/mock.

@grantr
Copy link
Contributor Author

grantr commented Jul 27, 2018

@droot Can you give an example of how mocks would be used for this? What interface would I mock?

@DirectXMan12
Copy link
Contributor

/kind feature

honestly, reactors might be a decent idea in theory, but in practice Kubernetes reactors tend to yield difficult-to-follow, brittle test code, IMO (as someone who's written or updated a number of reactor-based tests in the Kubernetes and OpenShift codebases)

we should think long and hard on the design before we opt for introducing them.

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 27, 2018
@DirectXMan12
Copy link
Contributor

They allow injecting errors

Generally possible with a real API server for most errors (not found, conflict, etc), but I can understand a desire to easily simulate others.

simulating the actions of other controllers

Simulating the actions of other controllers generally isn't particularly hard if you have something that can store objects (either an actual API server or something that just tracks objects), since controllers are just updating state through normal API calls.

and tracking the actions of the controller under test instead of just the output

I'd assert we probably want to discourage this behavior -- you should generally be tracking if the controller yielded the desired state, not how it does that (granted, there are times you want to ensure things happen in a certain order, but that's rarer, and often can be worked around by splitting up the actual method that does the sync and/or using requeues)

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 24, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 24, 2019
@DirectXMan12
Copy link
Contributor

closing for the moment. as outlined about, I don't think we actually want to support this

@khuddlefish
Copy link

khuddlefish commented Oct 3, 2019

@DirectXMan12 We ended up writing our own reactive client and wrapping it around the provided fake client to give ourselves the ability to use reactors. We found it pretty difficult to create the error states we wanted to test without the use of reactors. Our implementation is not the cleanest at the moment because we just wrote it for internal use, but we might be interested in polishing it up and sharing it, or helping to work those features into the provided client if there was interest. The option to not use reactors is always there if you don't like them, but I do think they can be a useful feature for testing and it would be nice to make them available.

@fiunchinho
Copy link

@khuddlefish do you have a public repo to take a look at? I'm interested on using reactors as well (or find a useful workaround).

@khuddlefish
Copy link

@fiunchinho Our implementation is not public right now I'm afraid. We might move it out of our internal repo and share it somewhere if we get the time and if there's enough interest. I can share with you a blog post we wrote about our process developing it though. I hope this is a bit helpful http://engineering.pivotal.io/post/gp4k-kubebuilder-tdd/

@DirectXMan12
Copy link
Contributor

@khuddlefish just as a heads up, the coloring on the syntax highlighting is almost impossible to read for me -- the grey used for the symbols fades into black background.

DirectXMan12 pushed a commit that referenced this issue Jan 31, 2020
fix the bug of recursion
@iamkirkbater
Copy link

@khuddlefish I'm digging into the same scenario you are, where I'm having a problem trying to mock specific errors (at the appropriate time) for our operator. If there's been any progress on opening the implementation you used to be able to mock the fake I would really appreciate if you have the ability to share it.

@iamkirkbater
Copy link

Sorry for pinging everyone again, but I wanted to update how we ended up accomplishing this for anyone who comes here in the future.

https://www.bater.io/posts/2020/06/throwing-errors-with-controller-runtime-fake/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

9 participants