- Notifications
You must be signed in to change notification settings - Fork 1.2k
🐛Implement priorityqueue as default on handlers if using priorityqueue interface #3111
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
🐛Implement priorityqueue as default on handlers if using priorityqueue interface #3111
Conversation
| /test pull-controller-runtime-test |
f7f9fbe to 753b14a Compare | I am not sure if you wanted to do this for the handler |
Yeah we would want this for all handlers we offer if possible. This PR is on my list but it might take me a few more days to find the time, sorry |
No rush, just wanted to understand the scope/ask of the issue and what work may still need to be done. |
pkg/handler/eventhandler.go Outdated
| | ||
| // addToPriorityQueueCreate adds the reconcile.Request to the priorityqueue in the handler | ||
| // for Create requests if and only if the workqueue being used is of type priorityqueue.PriorityQueue[reconcile.Request] | ||
| func addToPriorityQueueCreate[T client.Object](q priorityqueue.PriorityQueue[reconcile.Request], evt event.TypedCreateEvent[T], item reconcile.Request) { |
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 here, lets just wrap the handler in the constructor
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.
These are functions to not repeat the logic in the TypedEnqueueRequestForObject[T] Create/Update as we do export this type.
Do you want this to have a constructor to wrap with WithLowPriorityWhenUnchanged because this will require adding more constraints to deal with the func signature with ^^ to equal TypedEventHandler[object,request]. Unless I am misunderstanding something.
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.
Sorry I think I just commented on the wrong place here but I see you already updated it 👍
0f9055e to 8ef6629 Compare pkg/handler/eventhandler.go Outdated
| | ||
| // addToPriorityQueueCreate adds the reconcile.Request to the priorityqueue in the handler | ||
| // for Create requests if and only if the workqueue being used is of type priorityqueue.PriorityQueue[reconcile.Request] | ||
| func addToPriorityQueueCreate[T client.Object](q priorityqueue.PriorityQueue[reconcile.Request], evt event.TypedCreateEvent[T], item reconcile.Request) { |
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.
Sorry I think I just commented on the wrong place here but I see you already updated it 👍
| switch { | ||
| case !isNil(evt.ObjectNew): | ||
| q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ | ||
| item := reconcile.Request{NamespacedName: types.NamespacedName{ |
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.
Could we also do the same for Funcs? That is the only remaining handler
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.
Not sure if this is how you wanted this done but any feedback is appreciated.
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 think in Funcs we have to do the same dance as in TypedEnqueueRequestForObject because we export the type and not a constructor, otherwise the original goal of get this by default won't be achieved
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.
Makes sense, I did what we did with TypedEnqueueRequestForObject because I can't add methods to the Funcs type. So I did the same thing we did with this.
| /label tide-merge-method-squash |
| @alvaroaleman: The label(s) In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
aff6932 to eaf978d Compare pkg/handler/enqueue.go Outdated
| priorityQueue, isPriorityQueue := q.(priorityqueue.PriorityQueue[reconcile.Request]) | ||
| if !isPriorityQueue { | ||
| q.Add(item) | ||
| return | ||
| } |
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.
Should we also move this into the util func? (and rename the func to addToQueueCreate)
Same for update
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 can. I would have to move isObjectUnchanged as well. Not sure where to move it if we want that exposed or in some internal directory.
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.
Not sure what you mean :)
I only mean that these 5 lines should be inside of the addToQueueCreate func. I wouldn't move them to another package or export
(the util func == addToQueueCreate)
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.
Gotcha, I misunderstood. I can move them as well to do the check within the function. I did rename them but can move those lines inside.
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.
Sounds good. Just a lot of code we can deduplicate :)
pkg/handler/eventhandler.go Outdated
| return e.Object.GetCreationTimestamp().Time.Before(time.Now().Add(-time.Minute)) | ||
| } | ||
| | ||
| // addToPriorityQueueCreate adds the reconcile.Request to the priorityqueue in the handler |
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.
Would be good if we can use these two funcs in WithLowPriorityWhenUnchanged
10068c8 to 1d97d46 Compare pkg/handler/eventhandler.go Outdated
| } | ||
| | ||
| var _ EventHandler = Funcs{} | ||
| var _ EventHandler = &Funcs{} |
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 think this can not be a pointer receiver otherwise this is a breaking change 😬 Can we also typecheck that TypedFuncs which is now a different implementation is a TypedEventHandler?
1d97d46 to 8d804ba Compare 7aa17da to 5bbe24d Compare | Test logic needs updating because now that this is wrapped in the |
No, this should have no effect on existing functionality. I can see a bunch of panics in CI, so something seems to not be working correctly. |
58e6a86 to 90b1a3f Compare Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
489410a to a71f2cb Compare | @troy0820 how about you leave out EnqueueRequestFromMapFunc from this change and I will have a look into that one, as it seems a bit more tricky? |
That’ll work. I’ll queue up the change in a second. |
a71f2cb to 4e82bce Compare pkg/handler/eventhandler.go Outdated
| if ok { | ||
| evt, ok := any(e).(event.TypedCreateEvent[client.Object]) | ||
| if ok { | ||
| item := reconcile.Request{NamespacedName: types.NamespacedName{ |
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 isn't quite correct, because we need to run CreateFunc to know what item looks like, here we basically hardcode the same behavior as EnqueueRequestForObjec - Lets maybe leave the TypedFuncs out as well of this PR?
4e82bce to 1d0e50b Compare Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
1d0e50b to 16ff4af Compare 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.
Thanks!
| LGTM label has been added. Git tree hash: 3518285291eae78304b39908f55205b724196db9 |
| [APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, troy0820 The full list of commands accepted by this bot can be found here. The pull request process is described here Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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.
@troy0820 Thx for working on this!
Just one small finding, would be nice if you can follow-up
| // | ||
| // Unless you are implementing your own TypedEventHandler, you can ignore the functions on the TypedEventHandler interface. | ||
| // Most users shouldn't need to implement their own TypedEventHandler. | ||
| // |
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 change breaks godoc rendering of TypedEventHandler. Now only l.69 shows up
…e interface (kubernetes-sigs#3111) * implement priority queue for handlers Signed-off-by: Troy Connor <troy0820@users.noreply.github.com> * check object before placing in priorityqueue Signed-off-by: Troy Connor <troy0820@users.noreply.github.com> * implement priority queue Signed-off-by: Troy Connor <troy0820@users.noreply.github.com> --------- Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
Resolves #3105
Handlers:
TypedEnqueueRequestForObjectEnqueueRequestForOwnerEnqueueRequestFromMapFuncThis brings the handler
TypedEnqueueRequestForObject,enqueueRequestForOwnerandenqueuRequestFromMapFunchandlers to use priority queue if theworkqueue.TypedRateLimitingInterface[reconcile.Request]is of typepriorityqueue.PriorityQueue[reconcile.Request]without having to use the wrapperWithLowPriorityWhenUnchanged.NOTE: Added tests implement the same logic to show that this maps to the functionality of the wrapped handler in the tests
/assign @alvaroaleman @sbueringer