-
Notifications
You must be signed in to change notification settings - Fork 1.2k
How to correctly use context arguments is unclear #265
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
Comments
/kind feature |
I was wondering about this too, my understanding is the controller runtime doesn't enforce any timeout on reconciliation attempts, which could cause the entire controller to lock up: Doing something like this doesn't seem so bad: func (r *MyReconciler) Reconcile(req reconcile.Request) (reconcile.Result, error) {
ctx := context.WithTimeout(context.Background(), r.timeout)
instance := &api.MyCRD{}
_ = r.Get(ctx, request.NamespacedName, instane)
_ = r.someAPI.Call(ctx, &RPCRequest{})
// ...
} Though I could also see a new field on type Options struct {
MaxConcurrentReconciles int
ReconcilerTimeout time.Duration // default to a minute?
Reconciler reconcile.Reconciler
} Then have the controller pass in a context as part of the request: func (c *Controller) processNextWorkItem() bool {
if c.ReconcilerTimeout != time.Duration(0) {
req = req.WithContext(context.WithTimeout(context.Background(), c.ReconcilerTimeout))
}
if result, err := c.Do.Reconcile(req); err != nil {
// handle
}
} |
we can't actually enforce timeouts, but we can totally allow you to configure a timeout context builder that gets passed to all reconcile requests that you can pass to clients. It won't help if you manually block yourself, but in the case of well-behaved clients it's probably a good idea. |
since you might want contexts for other things, a |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle rotten |
I noticed today that Webhooks get invoked with |
/lifecycle frozen |
Putting my money where my mouth is, see #549. |
thanks, merged! |
/help |
@vincepri: Please ensure the request meets the requirements listed here. If this request no longer meets these requirements, the label can be removed 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. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/lifecycle frozen |
/remove-lifecycle frozen @coderanger Seems this issue can now be closed given that most functions and reconcilers accept a context starting from v0.7.x |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
/close Wow I had forgotten I wrote this :) |
@coderanger: Closing this issue. 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. |
Most of the examples use
context.TODO()
on each call into the client. Would be nice to have a better explanation of what this is for.And someday it would be cool to add a
.Context
field on thereconcile.Request
for controllers (and maybe something similar for webhooks, though that's harder), and have the controller machinery create acontext.Background()
at the start of a request so you can thread it down into calls to the client library and whatnot.The text was updated successfully, but these errors were encountered: