-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: main
Are you sure you want to change the base?
🐛Implement priorityqueue as default on handlers if using priorityqueue interface #3111
Conversation
/test pull-controller-runtime-test |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: troy0820 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 |
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 👍
} | ||
|
||
// Update implements EventHandler. | ||
func (e *TypedEnqueueRequestForObject[T]) Update(ctx context.Context, evt event.TypedUpdateEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { | ||
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
@@ -199,3 +205,23 @@ func (w workqueueWithCustomAddFunc[request]) Add(item request) { | |||
func isObjectUnchanged[object client.Object](e event.TypedCreateEvent[object]) bool { | |||
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
@@ -82,10 +83,72 @@ type TypedEventHandler[object any, request comparable] interface { | |||
Generic(context.Context, event.TypedGenericEvent[object], workqueue.TypedRateLimitingInterface[request]) | |||
} | |||
|
|||
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
Signed-off-by: Troy Connor <[email protected]>
8d804ba
to
29780d9
Compare
@troy0820: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
type Funcs = funcs[client.Object, reconcile.Request] | ||
|
||
// funcs implements eventhandler | ||
type funcs[object client.Object, request reconcile.Request] struct{} |
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.
Actually this is not correct, right now this is just a re-implementation of EnqueueRequestForOwner
😅 We need to have public properties for CreateFunc/UpdateFunc/DeleteFunc/GenericFunc and delegate to them just like we do in TypedFuncs
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.
Does Funcs
need to be it's own type? I can't add methods to Funcs
if it's a TypedFuncs[client.Object, reconcile.Request]
and declaring CreateFunc
methods causes an overflow of calls if I try to inject it in the h.CreateFunc(ctx, e, q)
call. 🤔
Do you want the default behavior of the priorityqueue
to be based on if the CreateFunc
is not defined?
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.
Do you want the default behavior of the priorityqueue to be based on if the CreateFunc is not defined?
I think if the CreateFunc
is not defined we should just not do anything just like we do today.
Maybe a better approach is to use Reflect
in TypedFuncs
to figure out if object
is assignable to client.Object
and request
is a reconcile.Request
and if so, use the helpers you added for EnqueueRequestForObject
? I did some of that in the Builder
because For
there can only be used if request
is a reconcile.Request
Resolves #3105
Handlers:
TypedEnqueueRequestForObject
EnqueueRequestForOwner
EnqueueRequestFromMapFunc
This brings the handler
TypedEnqueueRequestForObject
,enqueueRequestForOwner
andenqueuRequestFromMapFunc
handlers 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