-
Notifications
You must be signed in to change notification settings - Fork 1.3k
✨ Deduplicate events before sending them into the workqueue. #1390
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
Changes from 2 commits
cb3c054
341be59
337285a
28f3a5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,31 +59,37 @@ type EnqueueRequestForOwner struct { | |
|
|
||
| // Create implements EventHandler | ||
| func (e *EnqueueRequestForOwner) Create(evt event.CreateEvent, q workqueue.RateLimitingInterface) { | ||
| for _, req := range e.getOwnerReconcileRequest(evt.Object) { | ||
| reqs := map[reconcile.Request]empty{} | ||
| e.getOwnerReconcileRequest(evt.Object, reqs) | ||
| for req := range reqs { | ||
| q.Add(req) | ||
| } | ||
| } | ||
|
|
||
| // Update implements EventHandler | ||
| func (e *EnqueueRequestForOwner) Update(evt event.UpdateEvent, q workqueue.RateLimitingInterface) { | ||
| for _, req := range e.getOwnerReconcileRequest(evt.ObjectOld) { | ||
| q.Add(req) | ||
| } | ||
| for _, req := range e.getOwnerReconcileRequest(evt.ObjectNew) { | ||
| reqs := map[reconcile.Request]empty{} | ||
| e.getOwnerReconcileRequest(evt.ObjectOld, reqs) | ||
| e.getOwnerReconcileRequest(evt.ObjectNew, reqs) | ||
| for req := range reqs { | ||
| q.Add(req) | ||
| } | ||
| } | ||
|
|
||
| // Delete implements EventHandler | ||
| func (e *EnqueueRequestForOwner) Delete(evt event.DeleteEvent, q workqueue.RateLimitingInterface) { | ||
| for _, req := range e.getOwnerReconcileRequest(evt.Object) { | ||
| reqs := map[reconcile.Request]empty{} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed here and in Generic? I would have assumed that kube doesn't allow multiple identical ownerRefs
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I don't actually know what happens if you try to give the same non-controller owner twice.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I bet you could have duplicates,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I would prefer to omit that here and in Generic
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If not in Delete nor Generic, why have it in Create?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the code again, I think we should probably just leave it. It would complicate the flow to only do it sometimes, would have to switch back to returning a slice and then process it again, the extra memory allocations and code complexity seems not worth it. |
||
| e.getOwnerReconcileRequest(evt.Object, reqs) | ||
| for req := range reqs { | ||
| q.Add(req) | ||
| } | ||
| } | ||
|
|
||
| // Generic implements EventHandler | ||
| func (e *EnqueueRequestForOwner) Generic(evt event.GenericEvent, q workqueue.RateLimitingInterface) { | ||
| for _, req := range e.getOwnerReconcileRequest(evt.Object) { | ||
| reqs := map[reconcile.Request]empty{} | ||
| e.getOwnerReconcileRequest(evt.Object, reqs) | ||
| for req := range reqs { | ||
| q.Add(req) | ||
| } | ||
| } | ||
|
|
@@ -111,17 +117,16 @@ func (e *EnqueueRequestForOwner) parseOwnerTypeGroupKind(scheme *runtime.Scheme) | |
|
|
||
| // getOwnerReconcileRequest looks at object and returns a slice of reconcile.Request to reconcile | ||
| // owners of object that match e.OwnerType. | ||
| func (e *EnqueueRequestForOwner) getOwnerReconcileRequest(object metav1.Object) []reconcile.Request { | ||
|
coderanger marked this conversation as resolved.
|
||
| func (e *EnqueueRequestForOwner) getOwnerReconcileRequest(object metav1.Object, result map[reconcile.Request]empty) { | ||
| // Iterate through the OwnerReferences looking for a match on Group and Kind against what was requested | ||
| // by the user | ||
| var result []reconcile.Request | ||
| for _, ref := range e.getOwnersReferences(object) { | ||
| // Parse the Group out of the OwnerReference to compare it to what was parsed out of the requested OwnerType | ||
| refGV, err := schema.ParseGroupVersion(ref.APIVersion) | ||
| if err != nil { | ||
| log.Error(err, "Could not parse OwnerReference APIVersion", | ||
| "api version", ref.APIVersion) | ||
| return nil | ||
| return | ||
| } | ||
|
|
||
| // Compare the OwnerReference Group and Kind against the OwnerType Group and Kind specified by the user. | ||
|
|
@@ -138,18 +143,15 @@ func (e *EnqueueRequestForOwner) getOwnerReconcileRequest(object metav1.Object) | |
| mapping, err := e.mapper.RESTMapping(e.groupKind, refGV.Version) | ||
| if err != nil { | ||
| log.Error(err, "Could not retrieve rest mapping", "kind", e.groupKind) | ||
| return nil | ||
| return | ||
| } | ||
| if mapping.Scope.Name() != meta.RESTScopeNameRoot { | ||
| request.Namespace = object.GetNamespace() | ||
| } | ||
|
|
||
| result = append(result, request) | ||
| result[request] = empty{} | ||
| } | ||
| } | ||
|
|
||
| // Return the matches | ||
| return result | ||
| } | ||
|
|
||
| // getOwnersReferences returns the OwnerReferences for an object as specified by the EnqueueRequestForOwner | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.