package wait
import "github.com/google/go-containerregistry/internal/retry/wait"
Package wait is a subset of k8s.io/apimachinery to avoid conflicts in dependencies (specifically, logging).
Index ¶
- Variables
- func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error
- func Jitter(duration time.Duration, maxFactor float64) time.Duration
- type Backoff
- type ConditionFunc
Variables ¶
ErrWaitTimeout is returned when the condition exited without success.
Functions ¶
func ExponentialBackoff ¶
func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error
ExponentialBackoff repeats a condition check with exponential backoff.
It repeatedly checks the condition and then sleeps, using `backoff.Step()` to determine the length of the sleep and adjust Duration and Steps. Stops and returns as soon as: 1. the condition check returns true or an error, 2. `backoff.Steps` checks of the condition have been done, or 3. a sleep truncated by the cap on duration has been completed. In case (1) the returned error is what the condition function returned. In all other cases, ErrWaitTimeout is returned.
func Jitter ¶
Jitter returns a time.Duration between duration and duration + maxFactor * duration.
This allows clients to avoid converging on periodic behavior. If maxFactor is 0.0, a suggested default value will be chosen.
Types ¶
type Backoff ¶
type Backoff struct { // The initial duration. Duration time.Duration // Duration is multiplied by factor each iteration, if factor is not zero // and the limits imposed by Steps and Cap have not been reached. // Should not be negative. // The jitter does not contribute to the updates to the duration parameter. Factor float64 // The sleep at each iteration is the duration plus an additional // amount chosen uniformly at random from the interval between // zero and `jitter*duration`. Jitter float64 // The remaining number of iterations in which the duration // parameter may change (but progress can be stopped earlier by // hitting the cap). If not positive, the duration is not // changed. Used for exponential backoff in combination with // Factor and Cap. Steps int // A limit on revised values of the duration parameter. If a // multiplication by the factor parameter would make the duration // exceed the cap then the duration is set to the cap and the // steps parameter is set to zero. Cap time.Duration }
Backoff holds parameters applied to a Backoff function.
func (*Backoff) Step ¶
Step (1) returns an amount of time to sleep determined by the original Duration and Jitter and (2) mutates the provided Backoff to update its Steps and Duration.
type ConditionFunc ¶
ConditionFunc returns true if the condition is satisfied, or an error if the loop should be aborted.
Source Files ¶
kubernetes_apimachinery_wait.go
- Version
- v0.20.3 (latest)
- Published
- Jan 15, 2025
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 19 hours ago –
Tools for package owners.