Merge pull request #115113 from smarterclayton/exponential_context

wait: ExponentialBackoffWithContext should take context-aware fn
This commit is contained in:
Kubernetes Prow Robot 2023-01-20 07:38:15 -08:00 committed by GitHub
commit b0ed87078e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -716,7 +716,7 @@ func poller(interval, timeout time.Duration) waitWithContextFunc {
// ExponentialBackoffWithContext works with a request context and a Backoff. It ensures that the retry wait never // ExponentialBackoffWithContext works with a request context and a Backoff. It ensures that the retry wait never
// exceeds the deadline specified by the request context. // exceeds the deadline specified by the request context.
func ExponentialBackoffWithContext(ctx context.Context, backoff Backoff, condition ConditionFunc) error { func ExponentialBackoffWithContext(ctx context.Context, backoff Backoff, condition ConditionWithContextFunc) error {
for backoff.Steps > 0 { for backoff.Steps > 0 {
select { select {
case <-ctx.Done(): case <-ctx.Done():
@ -724,7 +724,7 @@ func ExponentialBackoffWithContext(ctx context.Context, backoff Backoff, conditi
default: default:
} }
if ok, err := runConditionWithCrashProtection(condition); err != nil || ok { if ok, err := runConditionWithCrashProtectionWithContext(ctx, condition); err != nil || ok {
return err return err
} }

View File

@ -878,7 +878,7 @@ func TestExponentialBackoffWithContext(t *testing.T) {
} }
attempts := 0 attempts := 0
err := ExponentialBackoffWithContext(test.ctxGetter(), backoff, func() (bool, error) { err := ExponentialBackoffWithContext(test.ctxGetter(), backoff, func(_ context.Context) (bool, error) {
attempts++ attempts++
return test.callback(attempts) return test.callback(attempts)
}) })

View File

@ -121,7 +121,7 @@ func WithExponentialBackoff(ctx context.Context, retryBackoff wait.Backoff, webh
// having a webhook error allows us to track the last actual webhook error for requests that // having a webhook error allows us to track the last actual webhook error for requests that
// are later cancelled or time out. // are later cancelled or time out.
var webhookErr error var webhookErr error
err := wait.ExponentialBackoffWithContext(ctx, retryBackoff, func() (bool, error) { err := wait.ExponentialBackoffWithContext(ctx, retryBackoff, func(_ context.Context) (bool, error) {
webhookErr = webhookFn() webhookErr = webhookFn()
if shouldRetry(webhookErr) { if shouldRetry(webhookErr) {
return false, nil return false, nil

View File

@ -673,7 +673,7 @@ func waitForDetachAndGrabMetrics(ctx context.Context, oldMetrics *storageControl
oldDetachCount = 0 oldDetachCount = 0
} }
verifyMetricFunc := func() (bool, error) { verifyMetricFunc := func(ctx context.Context) (bool, error) {
updatedMetrics, err := metricsGrabber.GrabFromControllerManager(ctx) updatedMetrics, err := metricsGrabber.GrabFromControllerManager(ctx)
if err != nil { if err != nil {
@ -821,7 +821,7 @@ func waitForPVControllerSync(ctx context.Context, metricsGrabber *e2emetrics.Gra
Factor: 1.2, Factor: 1.2,
Steps: 21, Steps: 21,
} }
verifyMetricFunc := func() (bool, error) { verifyMetricFunc := func(ctx context.Context) (bool, error) {
updatedMetrics, err := metricsGrabber.GrabFromControllerManager(ctx) updatedMetrics, err := metricsGrabber.GrabFromControllerManager(ctx)
if err != nil { if err != nil {
framework.Logf("Error fetching controller-manager metrics") framework.Logf("Error fetching controller-manager metrics")
@ -866,7 +866,7 @@ func waitForADControllerStatesMetrics(ctx context.Context, metricsGrabber *e2eme
Factor: 1.2, Factor: 1.2,
Steps: 21, Steps: 21,
} }
verifyMetricFunc := func() (bool, error) { verifyMetricFunc := func(ctx context.Context) (bool, error) {
updatedMetrics, err := metricsGrabber.GrabFromControllerManager(ctx) updatedMetrics, err := metricsGrabber.GrabFromControllerManager(ctx)
if err != nil { if err != nil {
e2eskipper.Skipf("Could not get controller-manager metrics - skipping") e2eskipper.Skipf("Could not get controller-manager metrics - skipping")