Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: treat rate limiter deadline as context deadline #635

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pkg/kstatus/polling/statusreaders/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func errResourceToResourceStatus(err error, resource *unstructured.Unstructured,
// If the error is from the context, we don't attach that to the ResourceStatus,
// but just return it directly so the caller can decide how to handle this
// situation.
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || errWouldExceedContextDeadline(err) {
return nil, err
}
identifier := object.UnstructuredToObjMetadata(resource)
Expand All @@ -193,7 +193,7 @@ func errIdentifierToResourceStatus(err error, identifier object.ObjMetadata) (*e
// If the error is from the context, we don't attach that to the ResourceStatus,
// but just return it directly so the caller can decide how to handle this
// situation.
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || errWouldExceedContextDeadline(err) {
return nil, err
}
if apierrors.IsNotFound(err) {
Expand All @@ -209,3 +209,15 @@ func errIdentifierToResourceStatus(err error, identifier object.ObjMetadata) (*e
Error: err,
}, nil
}

func errWouldExceedContextDeadline(err error) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for {
next := errors.Unwrap(err)
if next == nil {
break
}
err = next
}

return err != nil && err.Error() == "rate: Wait(n=1) would exceed context deadline"
}
13 changes: 13 additions & 0 deletions pkg/kstatus/polling/statusreaders/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ func TestLookupResource(t *testing.T) {
expectErr: true,
expectedErrMessage: context.Canceled.Error(),
},
"rate would exceed context deadline": {
identifier: deploymentIdentifier,
readerErr: fmt.Errorf("client rate limiter Wait returned an error: %w", fmt.Errorf("rate: Wait(n=1) would exceed context deadline")),
expectErr: true,
expectedErrMessage: "client rate limiter Wait returned an error: rate: Wait(n=1) would exceed context deadline",
},
"rate would exceed context deadline wrapped error": {
identifier: deploymentIdentifier,
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"))),
expectErr: true,
expectedErrMessage: "wrapped deeper: client rate limiter Wait returned an error: rate: Wait(n=1) would exceed context deadline",
},
}

for tn, tc := range testCases {
Expand Down