Skip to content

Commit 0ad87ef

Browse files
committed
fix: treat rate limiter deadline as context deadline
1 parent 0b156cb commit 0ad87ef

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

pkg/kstatus/polling/statusreaders/common.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func errResourceToResourceStatus(err error, resource *unstructured.Unstructured,
167167
// If the error is from the context, we don't attach that to the ResourceStatus,
168168
// but just return it directly so the caller can decide how to handle this
169169
// situation.
170-
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
170+
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || errWouldExceedContextDeadline(err) {
171171
return nil, err
172172
}
173173
identifier := object.UnstructuredToObjMetadata(resource)
@@ -193,7 +193,7 @@ func errIdentifierToResourceStatus(err error, identifier object.ObjMetadata) (*e
193193
// If the error is from the context, we don't attach that to the ResourceStatus,
194194
// but just return it directly so the caller can decide how to handle this
195195
// situation.
196-
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
196+
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || errWouldExceedContextDeadline(err) {
197197
return nil, err
198198
}
199199
if apierrors.IsNotFound(err) {
@@ -209,3 +209,15 @@ func errIdentifierToResourceStatus(err error, identifier object.ObjMetadata) (*e
209209
Error: err,
210210
}, nil
211211
}
212+
213+
func errWouldExceedContextDeadline(err error) bool {
214+
for {
215+
next := errors.Unwrap(err)
216+
if next == nil {
217+
break
218+
}
219+
err = next
220+
}
221+
222+
return err != nil && err.Error() == "rate: Wait(n=1) would exceed context deadline"
223+
}

pkg/kstatus/polling/statusreaders/common_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ func TestLookupResource(t *testing.T) {
7676
expectErr: true,
7777
expectedErrMessage: context.Canceled.Error(),
7878
},
79+
"rate would exceed context deadline": {
80+
identifier: deploymentIdentifier,
81+
readerErr: fmt.Errorf("client rate limiter Wait returned an error: %w", fmt.Errorf("rate: Wait(n=1) would exceed context deadline")),
82+
expectErr: true,
83+
expectedErrMessage: "client rate limiter Wait returned an error: rate: Wait(n=1) would exceed context deadline",
84+
},
85+
"rate would exceed context deadline wrapped error": {
86+
identifier: deploymentIdentifier,
87+
readerErr: fmt.Errorf("wrapped deeper: %w", fmt.Errorf("client rate limiter Wait returned an error: %w", fmt.Errorf("rate: Wait(n=1) would exceed context deadline"))),
88+
expectErr: true,
89+
expectedErrMessage: "wrapped deeper: client rate limiter Wait returned an error: rate: Wait(n=1) would exceed context deadline",
90+
},
7991
}
8092

8193
for tn, tc := range testCases {

0 commit comments

Comments
 (0)