Skip to content

Add configuration to limit number of requeues per item #3199

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

Open
jaredgorski opened this issue Apr 23, 2025 · 1 comment
Open

Add configuration to limit number of requeues per item #3199

jaredgorski opened this issue Apr 23, 2025 · 1 comment

Comments

@jaredgorski
Copy link

Consider the case where Reconcile calls an external API to notify it of some event and may receive an error. I can handle these errors explicitly within Reconcile to avoid some unnecessary requeues for terminal errors, but I may want to configure a default/backstop policy which requeues as normal (i.e. according to the rate limiter), but stops at a specified failureCount. In other words, make it easier to configure the controller to prevent endless requeueing of all "non-terminal" errors, and therefore prevent spamming the external API by default.

From what I can tell, the current way to do this "per-item requeue limit" is to roll a custom Controller implementation and call c.queue.Forget(item) within processNextWorkItem if the failureCount exceeds some hardcoded number. I see this logic present on some of the client-go examples.

Adding this to the controller builder options seems natural, since we already have RateLimiter and this is semi-related. The PerItemRequeueLimit option could default to 0, which we would treat as "infinity". Any int setting greater than zero would allow us to impose the limit by checking NumRequeues and, if the limit is violated, we emit metrics and bypass the requeue.

	log.V(5).Info("Reconciling")
	result, err := c.Reconcile(ctx, req)
	switch {
	case err != nil:
		if errors.Is(err, reconcile.TerminalError(nil)) {
			ctrlmetrics.TerminalReconcileErrors.WithLabelValues(c.Name).Inc()
		} else if c.PerItemRequeueLimit != 0 && c.Queue.NumRequeues(req) > c.PerItemRequeueLimit {
			ctrlmetrics.ExceededPerItemRequeueLimitReconcileErrors.WithLabelValues(c.Name).Inc()
		} else {
			c.Queue.AddWithOpts(priorityqueue.AddOpts{RateLimited: true, Priority: priority}, req)
		}
@jaredgorski
Copy link
Author

I'm willing to submit a PR if this feature seems acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant