-
Notifications
You must be signed in to change notification settings - Fork 105
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
controller: add TriggeredBy custom watches to engine #535
Conversation
@sttts This LGTM, but can you update the PR description with some context as to why we want this. Any context on how it's been tested would also help. |
Added context. |
pkg/controller/engine.go
Outdated
// TriggeredBy returns a custom watch for secondary resources triggering the | ||
// controller. Events will be handled by the supplied EventHandler, and may be | ||
// filtered by the supplied predicates. | ||
func TriggeredBy(cache cache.Cache, kind client.Object, h handler.EventHandler, p ...predicate.Predicate) Watch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it was tested e2e by https://github.com/crossplane/crossplane/pull/4582/files#diff-52e214a3e1aa3741fcbc3dd3faca4e6ae54e98b177690300591a4d147294a70dR416 ?
Do we want to extend unit tests at https://github.com/crossplane/crossplane-runtime/blob/master/pkg/controller/engine_test.go ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The engine is basically untested today. It only checks some errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so maybe we should separately track extending unit test coverage? I'll leave it up to you and not hold this one :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried now for 20min. You mock yourself to death with cache, informer, controller. At the end, you are not sure anymore what you are testing. There is a reason this is only lightly tested 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sttts got it, thanks a lot for checking! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this whole package is kinda just syntactic sugar. 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @sttts! The use case makes sense to me now. |
What is missing to merge this? |
fb1419c
to
d084614
Compare
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
d084614
to
eb74932
Compare
// controller. source.Kind can be used to create a source for a secondary cache. | ||
// Events will be handled by the supplied EventHandler, and may be filtered by | ||
// the supplied predicates. | ||
func TriggeredBy(source source.Source, h handler.EventHandler, p ...predicate.Predicate) Watch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@negz see that I slightly changed the signature. It's more flexible now.
Before: TriggeredBy(someCache, kind, h, p)
Now: TriggeredBy(source.Kind(someCache, kind), h, p)
Description of your changes
Added
controller.TriggeredBy
to create controller engine watches based on a different informer cache (the one from outside).This is helpful e.g. to trigger the compositor reconciling XRs through changes on
CompositionRevision
. The compositor has its own informer cache because it is dynamically started for each XR kind, done using the controller engine. This kind of controllers though today can only watch objects in the same cache. This PR adds a way to inject watches from another cache, e.g. the top-level cache watching theCompositionRevision
kind.I have:
make reviewable test
to ensure this PR is ready for review.How has this code been tested
This has been tested as part of crossplane/crossplane#4582, manually for the demo in that PR, plus I am working on tests for it.