Rolling my own exponential backoff #2506
-
I'm aware of the exponential backoff provided by kubebuilder: return an error or just set requeue to true. This causes controller-runtime to requeue with exponential backoff. What id I want the exponential backoff to start slower than just a few milliseconds? The reason is to avoid bing rate-limited by other APIs. For example, in my reconcile, I might determine that object X failed to reconcile, and should be reconciled after ~1 second, and if it fails, retry, but exponentially backing off at ~2 seconds, then ~4 and so on. The same as what controller run-time does now, except skip the first second of exponentially backing off. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I'm thinking something like a
This would have the following effect for these "Denied" objects:
|
Beta Was this translation helpful? Give feedback.
-
Hi @mogsie, I understand that the error that you are facing is Implementing a denyBefore map, as you described, can help introduce an intentional delay before requeueing. This can give other concurrent operations a chance to complete and thus reduce the chances of subsequent conflicts. The ideal approach to sort out this scenario is fetch the resource before update as it is implemented when you use the Deploy Image plugin to generate the scaffold, see the controller implementation under the testdata samples, such as here: https://github.com/kubernetes-sigs/kubebuilder/blob/689360500f8c218f69f2aa47aaa26da26b179e16/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller.go#L109C3-L118 On top of that see that:
Then, if you want change since it would might either consider proposal Controller-Runtime Enhancements and discuss that in their repository. Therefore, I am closing this one as sorted out |
Beta Was this translation helpful? Give feedback.
Hi @mogsie,
I understand that the error that you are facing is
the object has been modified, please apply your changes to the latest version and try again
which is indicative of a conflict due to concurrent updates on the same Kubernetes resource. When this happens, your reconciler will fail and, by default, will immediately requeue the request, potentially exacerbating the problem.Implementing a denyBefore map, as you described, can help introduce an intentional delay before requeueing. This can give other concurrent operations a chance to complete and thus reduce the chances of subsequent conflicts.
The ideal approach to sort out this scenario is fetch the resource before update as it …