mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
wait: Group ExponentialBackoff* functions together in file
No code change other than movement.
This commit is contained in:
parent
fcfe5dfc21
commit
df3e8ee175
@ -439,6 +439,35 @@ func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error {
|
|||||||
return ErrWaitTimeout
|
return ErrWaitTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExponentialBackoffWithContext works with a request context and a Backoff. It ensures that the retry wait never
|
||||||
|
// exceeds the deadline specified by the request context.
|
||||||
|
func ExponentialBackoffWithContext(ctx context.Context, backoff Backoff, condition ConditionWithContextFunc) error {
|
||||||
|
for backoff.Steps > 0 {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok, err := runConditionWithCrashProtectionWithContext(ctx, condition); err != nil || ok {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if backoff.Steps == 1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
waitBeforeRetry := backoff.Step()
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
case <-time.After(waitBeforeRetry):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ErrWaitTimeout
|
||||||
|
}
|
||||||
|
|
||||||
// Poll tries a condition func until it returns true, an error, or the timeout
|
// Poll tries a condition func until it returns true, an error, or the timeout
|
||||||
// is reached.
|
// is reached.
|
||||||
//
|
//
|
||||||
@ -713,32 +742,3 @@ func poller(interval, timeout time.Duration) waitWithContextFunc {
|
|||||||
return ch
|
return ch
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExponentialBackoffWithContext works with a request context and a Backoff. It ensures that the retry wait never
|
|
||||||
// exceeds the deadline specified by the request context.
|
|
||||||
func ExponentialBackoffWithContext(ctx context.Context, backoff Backoff, condition ConditionWithContextFunc) error {
|
|
||||||
for backoff.Steps > 0 {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return ctx.Err()
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok, err := runConditionWithCrashProtectionWithContext(ctx, condition); err != nil || ok {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if backoff.Steps == 1 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
waitBeforeRetry := backoff.Step()
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return ctx.Err()
|
|
||||||
case <-time.After(waitBeforeRetry):
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrWaitTimeout
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user