controller-runtime icon indicating copy to clipboard operation
controller-runtime copied to clipboard

Add configuration to limit number of requeues per item

Open jaredgorski opened this issue 8 months ago • 1 comments

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 avatar Apr 23 '25 21:04 jaredgorski

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

jaredgorski avatar Apr 23 '25 21:04 jaredgorski

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jul 22 '25 22:07 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Aug 21 '25 22:08 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Sep 20 '25 22:09 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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-sigs/prow repository.

k8s-ci-robot avatar Sep 20 '25 22:09 k8s-ci-robot