Skip to content
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

Document ways to trigger/not trigger exponential backoff #808

Open
djzager opened this issue Feb 20, 2020 · 11 comments
Open

Document ways to trigger/not trigger exponential backoff #808

djzager opened this issue Feb 20, 2020 · 11 comments
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/documentation Categorizes issue or PR as related to documentation. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete.
Milestone

Comments

@djzager
Copy link
Contributor

djzager commented Feb 20, 2020

Related to #617

As a user of controller-runtime, it is not immediately clear what returns from a Reconcile() will force a requeue with (or without) an exponential backoff. Some quick examples:

return reconcile.Result{requeue: true}, nil

return reconcile.Result{requeueAfter: time.Duration(60) * time.Second}, nil

// err != nil
return reconcile.Result{}, fmt.Errorf("My custom error string")
@djzager
Copy link
Contributor Author

djzager commented Feb 20, 2020

/kind documentation

@k8s-ci-robot k8s-ci-robot added the kind/documentation Categorizes issue or PR as related to documentation. label Feb 20, 2020
@djzager
Copy link
Contributor Author

djzager commented Feb 20, 2020

I see mentions of backoff in

// TODO(directxman12): we should ensure that backoff occurrs with error requeue
It("should not reset backoff until there's a non-error result", func() {

I think the two potential landing spots for documenting the requeue/backoff behavior would be:

  1. in the godoc for controller-runtime (either in the controller directly or in workqueue?)
  2. in the kubebuilder book (maybe here?). This would require a separate issue against github.com/kubernetes-sigs/kubebuilder

@vincepri vincepri added this to the v0.5.x milestone Feb 20, 2020
@vincepri
Copy link
Member

/priority important-longterm
/help

@k8s-ci-robot
Copy link
Contributor

@vincepri:
This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

/priority important-longterm
/help

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.

@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Feb 20, 2020
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 20, 2020
@vincepri
Copy link
Member

/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 20, 2020
@cflewis
Copy link
Contributor

cflewis commented Jun 5, 2020

I care about this. I spent a couple days writing code to do this and then someone on my team said "maybe this is a Kubebuilder feature" which got me to here.

What do I need to do to make an exponential backoff during a reconcile happen?

@vincepri
Copy link
Member

vincepri commented Jun 5, 2020

@cflewis Today, you only need to return an error to make it go in exponential backoff loop.

@cflewis
Copy link
Contributor

cflewis commented Jun 5, 2020 via email

@djzager
Copy link
Contributor Author

djzager commented Jun 8, 2020

You can configure the Rate Limiter on the Options to the Controller you create: https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/controller/controller.go#L40-L43

I noticed that the ratelimiter mentioned is internal to controller runtime but I believe it is intentionally identical to the one provided in client-go https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/ratelimiter/ratelimiter.go#L21-L30

https://godoc.org/k8s.io/client-go/util/workqueue#RateLimiter for more information about rate limiters. You may be specifically interested in https://github.com/kubernetes/client-go/blob/master/util/workqueue/default_rate_limiters.go#L77-L83

I haven't tested this, but taking from the example provided in the godoc:

// Create a new Controller that will call the provided Reconciler function in response
// to events.
c, err := controller.New("pod-controller", mgr, controller.Options{
    Reconciler: reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) {
        // Your business logic to implement the API by creating, updating, deleting objects goes here.
        return reconcile.Result{}, nil
    }),
   RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(baseDelay, maxDelay),
})
if err != nil {
    log.Error(err, "unable to create pod-controller")
    os.Exit(1)
}

Hope this helps.

@cflewis
Copy link
Contributor

cflewis commented Jun 8, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/documentation Categorizes issue or PR as related to documentation. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete.
Projects
None yet
Development

No branches or pull requests

5 participants