retry

package
v1.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 2 Imported by: 4

README

pkg/util/retry

Intention

pkg/util/retry is a minimal polling-style retry helper. It is not a general retry-policy framework. Its job is to keep retrying a callback until it succeeds or until the caller's context is cancelled.

This package exists largely for historical convenience. It is useful for simple standalone waits and short polling loops, but it is not the platform's preferred model for controller reconciliation progress.

It currently provides:

  • Forever() to construct a retrier with a fixed one-second retry period
  • Do() and DoWithContext() to run the callback immediately and then keep retrying until success or cancellation
  • retry.Error to preserve both the context cancellation error and the last callback failure when the loop exits because the context ended

Invariants And Guard Rails

  • The callback is invoked immediately before any waiting occurs.
  • If the callback continues to fail, retries happen every second until success or context cancellation.
  • Do() uses context.TODO(). DoWithContext() is the path to use when cancellation or timeout semantics matter.
  • On cancellation, the returned retry.Error preserves both why the loop stopped and what the callback was still failing with.
  • This helper is acceptable for a small number of simple blocking poll loops where returning control to a framework is not the right model. It should not be treated as the default retry primitive for new workflow code.

Caveats

  • The fixed one-second retry period is historical simplicity, not a carefully tuned repository-wide retry policy.
  • This package does not provide backoff, jitter, retry budgets, selective retry by error type, or observability hooks.
  • This is not the preferred primitive for controller-runtime reconciler progress. In reconciler code, the platform generally prefers yielding back to controller-runtime and using requeue/retry semantics so reconciliation stays non-blocking and fair.
  • Using this helper inside long-running reconciliation paths can work against the fairness and controlled-retry behavior provided elsewhere in the platform.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func() error

Callback is a callback that must return nil to escape the retry loop.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error allows the last error to be retrieved.

func (*Error) Callback

func (e *Error) Callback() error

Callback gets the last callback error.

func (*Error) Context

func (e *Error) Context() error

Context gets the context error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Unwrap

func (e *Error) Unwrap() []error

Unwrap allows access to either of the errors via errors.Is or errors.As.

type Retrier

type Retrier struct {
	// contains filtered or unexported fields
}

Retrier implements retry loop logic.

func Forever

func Forever() *Retrier

Froever returns a retrier that will retry soething forever until a nil error is returned.

func (*Retrier) Do

func (r *Retrier) Do(f Callback) error

Do starts the retry loop. It will run until success or until an optional timeout expires.

func (*Retrier) DoWithContext

func (r *Retrier) DoWithContext(c context.Context, f Callback) error

DoWithContext allows you to use a global context to interrupt execution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL