-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
🌱 remove redundant watch event handlers via Owns()
#10048
🌱 remove redundant watch event handlers via Owns()
#10048
Conversation
Hi @adityabhatia. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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/test-infra repository. |
Watches()
for resources implemented with Owns()
Watches()
for resources implemented with Owns()
@adityabhatia: 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/test-infra repository. |
/area machine |
@adityabhatia let me know when/if I should take a look (I'm ignoring WIP PRs per default if nobody asks for a review) |
Sure please have a look. I wanted to create an issue for it, explaining the goal (to do a feasibility check). Eg.
here |
Owns(&clusterv1.MachineSet{}). | ||
Watches( | ||
&clusterv1.MachineSet{}, | ||
handler.EnqueueRequestsFromMapFunc(r.MachineSetToDeployments), | ||
). |
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 is only equivalent to Owns if we basically implement the same thing. But MachineSetToDeployments does more than that. I assume because we can't always rely on ownerRefs
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, the labels are there as backup. Going by that logic, now thinking from the opposite perspective wouldn't Owns()
be redundant?
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.
Assuming our implementation is bug free (which should be easy to verify). Yes!
2688d4a
to
4b3755f
Compare
4b3755f
to
4af481f
Compare
Watches()
for resources implemented with Owns()
Owns()
@@ -82,7 +82,6 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt | |||
|
|||
err = ctrl.NewControllerManagedBy(mgr). | |||
For(&clusterv1.MachineDeployment{}). |
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 took a closer look into the mapping functions. Looks like they don't enqueue at all based on ownerRefs
// Check if the controller reference is already set and
// return an empty result when one is found.
for _, ref := range ms.ObjectMeta.GetOwnerReferences() {
if ref.Controller != nil && *ref.Controller {
return result
}
}
I think the goal of these function is to only enqueue if owner is not set. And Owns
then takes care of it once the owner is set.
// MachineSetToDeployments is a handler.ToRequestsFunc to be used to enqueue requests for reconciliation
// for MachineDeployments that might adopt an orphaned MachineSet.
func (r *Reconciler) MachineSetToDeployments(ctx context.Context, o client.Object) []ctrl.Request {
Maybe we should add the comment here in the builder as well? (and of course keep Owns)
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.
@adityabhatia WDYT?
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.
Sry somehow lost track of this PR, I added comments now.
4af481f
to
06ac612
Compare
Thank you! /lgtm |
LGTM label has been added. Git tree hash: bb67874ce29a28459d0f7339124d389f3d6c690d
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sbueringer 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 |
/ok-to-test |
What this PR does / why we need it:
Owns()
watches for child resources and enqueues requests for owners (owner reference) with controller reference. This PR aims at removingOwns()
where such enqueuing is already in place viaWatches()
, thereby removing both redundant watch and enqueuing of resources.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #