-
Notifications
You must be signed in to change notification settings - Fork 1.2k
✨Add predicates as variadic args for Owns, For, and Watches func #602
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
Conversation
1b4ff4d
to
3658a3c
Compare
Discussed with @DirectXMan12 and he has right, DoAThing(cb func(runtime.Obj) *ctrl.Builder) then the compiler will throw an error. Because of that, this will be postponed |
we'll roll this in to the next set of breaking changes. I'll add a milestone or somesuch |
@mszostok Are you still interested / do you have time to work on this? |
Hi @vincepri Yes, if you are interested in having that functionality then I can fix it. You have some deadline? Because I can do it even tomorrow:) |
@mszostok Either this week / next week would be great to have this merged :) we're trying to get to a release soon-ish. Thank you for your help! |
@mszostok If you need a pair on this, I'm available too. 👍 on getting this landed. |
(lmk if you need someone to force-push a rebase here) |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mszostok The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@mszostok Is this PR ready to be reviewed in more depth? Is it still a draft? |
I'm gonna fix this up. I'm pretty sure this is ready. |
pkg/builder/controller.go
Outdated
IsController: true, | ||
} | ||
if err := blder.ctrl.Watch(src, hdler, blder.predicates...); err != nil { | ||
allPredicates := append(blder.globalPredicates, obj.predicates...) |
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.
this needs to be a copy first, otherwise you'll end up growing the list with other objects' predicates.
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.
(or, rather, you could, depending on what Go decides to do with the slice)
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.
you are right I missed it
This allows per-watch predicates for For, Owns, and Watches in the builder. These are in addition to the global predicate set, which apply to all watches.
83965e4
to
4c1d0e4
Compare
Should be good now |
(or rather, it looks good to me) |
return blder | ||
} | ||
|
||
// Owns defines types of Objects being *generated* by the ControllerManagedBy, and configures the ControllerManagedBy to respond to | ||
// create / delete / update events by *reconciling the owner object*. This is the equivalent of calling | ||
// Watches(&source.Kind{Type: <ForType-apiType>}, &handler.EnqueueRequestForOwner{OwnerType: apiType, IsController: true}) | ||
func (blder *Builder) Owns(apiType runtime.Object) *Builder { | ||
blder.managedObjects = append(blder.managedObjects, apiType) | ||
func (blder *Builder) Owns(apiType runtime.Object, prct ...predicate.Predicate) *Builder { |
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.
@DirectXMan12 Is this the best way to add this functionality? Having varargs here prevents us to add more functionality in the future if we wanted to expose more configurable options.
We could opt instead for a generic interface, similar for what we do for client.List
for example.
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.
yep, it is a functional options pattern and it could be better in that case at the beginning I just do not want to make it to complicated because I thought I will not break a contract
allPredicates := append([]predicate.Predicate(nil), blder.globalPredicates...) | ||
allPredicates = append(allPredicates, w.predicates...) |
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.
This could be simplified with
allPredicates := append(blder.globalPredicates, w.predicates...)
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 was like that at the beginning but @DirectXMan12 is right, it should be copied: #602 (comment)
// For defines the type of Object being *reconciled*, and configures the ControllerManagedBy to respond to create / delete / | ||
// update events by *reconciling the object*. | ||
// This is the equivalent of calling | ||
// Watches(&source.Kind{Type: apiType}, &handler.EnqueueRequestForObject{}) | ||
func (blder *Builder) For(apiType runtime.Object) *Builder { | ||
blder.apiType = apiType | ||
func (blder *Builder) For(reconciledAPIType runtime.Object, prct ...predicate.Predicate) *Builder { |
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.
func (blder *Builder) For(reconciledAPIType runtime.Object, prct ...predicate.Predicate) *Builder { | |
func (blder *Builder) For(object runtime.Object, predicates ...predicate.Predicate) *Builder { |
No need for shorter names
// simpleWatch represents the information required to construct a "simple" For | ||
// or Owns watch. | ||
type simpleWatch struct { | ||
item runtime.Object |
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.
item runtime.Object | |
object runtime.Object |
allPredicates := append([]predicate.Predicate(nil), blder.globalPredicates...) | ||
allPredicates = append(allPredicates, obj.predicates...) |
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.
This could be simplified with
allPredicates := append(blder.globalPredicates, w.predicates...)
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.
same as here: #602 (comment)
@vincepri @DirectXMan12 should I change it to functional options pattern as described here? #602 (comment) I can do it today |
Hi @vincepri @DirectXMan12 so I provided implementation with Functional options. Here is PR: #799 I've prepared a dedicated pull request so you can check which option is better. |
closing in favor of: #799 |
Description
Predicate
. Watches, Owns, For, and WatchesFixes: #572