Skip to content

Commit 1afcd7d

Browse files
authored
Merge pull request kubernetes#81902 from MikeSpreitzer/fix81888
Updated comments in wait.go
2 parents 9a5dc8f + 529a168 commit 1afcd7d

File tree

1 file changed

+27
-19
lines changed
  • staging/src/k8s.io/apimachinery/pkg/util/wait

1 file changed

+27
-19
lines changed

staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,31 @@ type ConditionFunc func() (done bool, err error)
207207
type Backoff struct {
208208
// The initial duration.
209209
Duration time.Duration
210-
// Duration is multiplied by factor each iteration. Must be greater
211-
// than or equal to zero.
210+
// Duration is multiplied by factor each iteration, if factor is not zero
211+
// and the limits imposed by Steps and Cap have not been reached.
212+
// Should not be negative.
213+
// The jitter does not contribute to the updates to the duration parameter.
212214
Factor float64
213-
// The amount of jitter applied each iteration. Jitter is applied after
214-
// cap.
215+
// The sleep at each iteration is the duration plus an additional
216+
// amount chosen uniformly at random from the interval between
217+
// zero and `jitter*duration`.
215218
Jitter float64
216-
// The number of steps before duration stops changing. If zero, initial
217-
// duration is always used. Used for exponential backoff in combination
218-
// with Factor.
219+
// The remaining number of iterations in which the duration
220+
// parameter may change (but progress can be stopped earlier by
221+
// hitting the cap). If not positive, the duration is not
222+
// changed. Used for exponential backoff in combination with
223+
// Factor and Cap.
219224
Steps int
220-
// The returned duration will never be greater than cap *before* jitter
221-
// is applied. The actual maximum cap is `cap * (1.0 + jitter)`.
225+
// A limit on revised values of the duration parameter. If a
226+
// multiplication by the factor parameter would make the duration
227+
// exceed the cap then the duration is set to the cap and the
228+
// steps parameter is set to zero.
222229
Cap time.Duration
223230
}
224231

225-
// Step returns the next interval in the exponential backoff. This method
226-
// will mutate the provided backoff.
232+
// Step (1) returns an amount of time to sleep determined by the
233+
// original Duration and Jitter and (2) mutates the provided Backoff
234+
// to update its Steps and Duration.
227235
func (b *Backoff) Step() time.Duration {
228236
if b.Steps < 1 {
229237
if b.Jitter > 0 {
@@ -271,14 +279,14 @@ func contextForChannel(parentCh <-chan struct{}) (context.Context, context.Cance
271279

272280
// ExponentialBackoff repeats a condition check with exponential backoff.
273281
//
274-
// It checks the condition up to Steps times, increasing the wait by multiplying
275-
// the previous duration by Factor.
276-
//
277-
// If Jitter is greater than zero, a random amount of each duration is added
278-
// (between duration and duration*(1+jitter)).
279-
//
280-
// If the condition never returns true, ErrWaitTimeout is returned. All other
281-
// errors terminate immediately.
282+
// It repeatedly checks the condition and then sleeps, using `backoff.Step()`
283+
// to determine the length of the sleep and adjust Duration and Steps.
284+
// Stops and returns as soon as:
285+
// 1. the condition check returns true or an error,
286+
// 2. `backoff.Steps` checks of the condition have been done, or
287+
// 3. a sleep truncated by the cap on duration has been completed.
288+
// In case (1) the returned error is what the condition function returned.
289+
// In all other cases, ErrWaitTimeout is returned.
282290
func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error {
283291
for backoff.Steps > 0 {
284292
if ok, err := condition(); err != nil || ok {

0 commit comments

Comments
 (0)