-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Consider using generics for the reconcile.Reconciler interface #2221
Comments
This is interesting. We might need to rework how the Controller handles the internal workqueue and instead of adding requests, it also passes in the object that's being reconciled, if any. |
No, the workqueue needs to store identifiers only to be able to de-duplicate. We need a controller implementation or maybe a reconciler wrapper that takes a client, is configured with the right object, returns if it is not found or calls the typed reconciler if it is found. |
Ah so you don't want the events' objects, but rather do a new Get call? |
Yeah exactly because at the time the object gets reconciled it might have been deleted. This is really just about elimnating the We have a downstream wrapper to do this and I thought that something like that would make a lot of sense to be upstreamed. |
Sounds good to me! |
We came up with this implementation for our usage: https://github.com/aws/karpenter-core/blob/main/pkg/operator/controller/typed.go which is potentially a step further than you want to go with the |
Why does this need generics? Would (edit: I misread the original post so the comments below aren't valid)
|
@nathanperkins the issue is titled "Consider using generics", so this is up for debate. We are unlikely to break the
Do you mind elaborating on what kind of deletion hendling would be broken by this? |
(edit: I misread the original post so the comments below aren't valid)
Any controller which has to maintain some internal state or cache about the objects it is reconciling. One example is if you use mapping functions, you might cache the information you need to make mapping decisions. This may be preferable to using client.List in the mapping function since client.List can fail and the mapping functions don't have any error handling or retries. |
I know, that is what the issue body states.
Okay, interesting approach. How do you ensure that data exists prior to the handler being used? It also means that the cached mapping data might be arbitrarily outdated or not? |
My bad, I don't know how I misread that. Sorry about that. I don't have any problems with a new interface. I generally avoid generics unless absolutely necessary. But I suppose it allows us to write the reconcilers without having to do a type assertion? Would this automatically fulflll the interface without having to explicitly specify the generic type?
If so, that sounds cool to me.
If the cached data is missing or out of date, it's usually because the object has changed and there would already be a request queued for it. In that case, mapping an event to that object would be redundant. |
Yes, exactly
It would need to be |
Most reconcilers reconcile some kubernetes object. Any such reconciler needs to start off with a check if the object still exists and do nothing if not. We could avoid this check by doing it in controller-runtime and adding a new interface
Reconcile[o ctrlclient.Object](context.Context, o)(reconcile.Result, error)
that people can use instead of the current one. We can not remove the current one, because not all reconcilers act on k8s objects.The main challenge here is that there are also reconcilers that do not reconcile a kubernetes object and that need to be able to use some kind of arbitrary key.
/cc @sbueringer @vincepri
The text was updated successfully, but these errors were encountered: