From 6acbe7e6452a44057768c61909da2d5b7c878159 Mon Sep 17 00:00:00 2001 From: Abu Kashem Date: Thu, 24 Feb 2022 17:28:01 -0500 Subject: [PATCH] client-go: chain the error returned by rate limiter --- staging/src/k8s.io/client-go/rest/request.go | 4 +++- test/integration/client/cert_rotation_test.go | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/client-go/rest/request.go b/staging/src/k8s.io/client-go/rest/request.go index 93bed5b9504..86f51229e12 100644 --- a/staging/src/k8s.io/client-go/rest/request.go +++ b/staging/src/k8s.io/client-go/rest/request.go @@ -504,7 +504,9 @@ func (r *Request) tryThrottleWithInfo(ctx context.Context, retryInfo string) err now := time.Now() err := r.rateLimiter.Wait(ctx) - + if err != nil { + err = fmt.Errorf("client rate limiter Wait returned an error: %w", err) + } latency := time.Since(now) var message string diff --git a/test/integration/client/cert_rotation_test.go b/test/integration/client/cert_rotation_test.go index b20c48be867..282ddf17c73 100644 --- a/test/integration/client/cert_rotation_test.go +++ b/test/integration/client/cert_rotation_test.go @@ -23,6 +23,7 @@ import ( "crypto/x509" "crypto/x509/pkix" "encoding/pem" + "errors" "math" "math/big" "os" @@ -135,7 +136,9 @@ func TestCertRotationContinuousRequests(t *testing.T) { for range time.Tick(time.Second) { _, err := client.CoreV1().ServiceAccounts("default").List(ctx, v1.ListOptions{}) if err != nil { - if err == ctx.Err() { + // client may wrap the context.Canceled error, so we can't + // do 'err == ctx.Err()', instead use 'errors.Is'. + if errors.Is(err, context.Canceled) { return }