Git Product home page Git Product logo

Comments (14)

iamkirkbater avatar iamkirkbater commented on August 15, 2024 1

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.

droot avatar droot commented on August 15, 2024

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

from controller-runtime.

droot avatar droot commented on August 15, 2024

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

from controller-runtime.

grantr avatar grantr commented on August 15, 2024

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

from controller-runtime.

DirectXMan12 avatar DirectXMan12 commented on August 15, 2024

/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.

DirectXMan12 avatar DirectXMan12 commented on August 15, 2024

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.

fejta-bot avatar fejta-bot commented on August 15, 2024

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.

fejta-bot avatar fejta-bot commented on August 15, 2024

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.

DirectXMan12 avatar DirectXMan12 commented on August 15, 2024

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

from controller-runtime.

khuddlefish avatar khuddlefish commented on August 15, 2024

@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.

fiunchinho avatar fiunchinho commented on August 15, 2024

@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.

khuddlefish avatar khuddlefish commented on August 15, 2024

@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.

DirectXMan12 avatar DirectXMan12 commented on August 15, 2024

@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.

iamkirkbater avatar iamkirkbater commented on August 15, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.