Comments (14)
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/
from controller-runtime.
@fanzhangio Can you investigate how hard it will be to add reactors ?
from controller-runtime.
@grantr Have you considered using https://github.com/golang/mock.
from controller-runtime.
@droot Can you give an example of how mocks would be used for this? What interface would I mock?
from controller-runtime.
/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.
from controller-runtime.
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)
from controller-runtime.
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
from controller-runtime.
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
from controller-runtime.
closing for the moment. as outlined about, I don't think we actually want to support this
from controller-runtime.
@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.
from controller-runtime.
@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).
from controller-runtime.
@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/
from controller-runtime.
@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.
from controller-runtime.
@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.
from controller-runtime.
Related Issues (20)
- Multi Cluster Example / Pattern HOT 9
- Panic in `runnableGroup`'s `Add` and `StopAndWait` due to a data race HOT 1
- Cannot run / install specific versions of setup-envtest due to missing submodule tag HOT 2
- Data race during manager shutdown HOT 4
- Add a validation script to verify go.mod is in sync with k/k HOT 3
- Enhancement of Authentication and Authorization Filters to Allow Custom Configurations and Stability Improvements HOT 4
- Data race with various client APIs HOT 3
- Allow to ignore globalPredicates for specific resources HOT 1
- Undefined SwitchMetric Error with client-go 0.30.0 in Go Vet HOT 9
- Use setup-envtest from (test) code HOT 18
- Semantic version is incorrect for setup-envtest HOT 3
- Default Liveness and Readiness endpoints return 404
- Optimize patches returned by Defaulter
- DefaultLabelSelector overrides ByObject.Label in DefaultNamespaces
- Does controller-runtime support that multiple controllers share one Manager and use different clients(RBAC)? HOT 6
- Add a way to grab the controller name out of the reconcile context HOT 1
- failed to install setup-envtest HOT 1
- How to change DefaultNamespaces at runtime HOT 3
- Reconcile is triggered after status update HOT 5
- Upgrade problem (v0.15.2->v0.17.3): configuring namespace HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from controller-runtime.