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

controller: add TriggeredBy custom watches to engine #535

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Sep 6, 2023

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 the CompositionRevision kind.

I have:

  • Read and followed Crossplane's contribution process.
  • Run 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.

@sttts sttts requested review from a team as code owners September 6, 2023 14:54
@sttts sttts requested review from negz and ytsarev September 6, 2023 14:54
@sttts sttts changed the title WIP: controller: add TriggeredBy custom watches to engine controller: add TriggeredBy custom watches to engine Sep 9, 2023
@negz
Copy link
Member

negz commented Sep 11, 2023

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

@sttts
Copy link
Contributor Author

sttts commented Sep 12, 2023

Added context.

// 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 {
Copy link
Member

@ytsarev ytsarev Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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 🤷

Copy link
Member

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! 👍

Copy link
Member

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

Copy link
Member

@ytsarev ytsarev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@negz
Copy link
Member

negz commented Sep 15, 2023

Thanks @sttts! The use case makes sense to me now.

@sttts
Copy link
Contributor Author

sttts commented Sep 16, 2023

What is missing to merge this?

// 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 {
Copy link
Contributor Author

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)

@turkenh turkenh merged commit 960a14f into crossplane:master Sep 19, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants