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
11 changes: 9 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,10 @@ func errIdentifierToResourceStatus(err error, identifier object.ObjMetadata) (*e
Error: err,
}, nil
}

func errWouldExceedContextDeadline(err error) bool {
if e := errors.Unwrap(err); e != nil {
return e.Error() == "rate: Wait(n=1) would exceed context deadline"
Copy link
Member

Choose a reason for hiding this comment

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

This is very fragile. There should be at least a test for this. Ideally the wait package should have a type for this.

Also, this doesn't feel like the right spot for this logic.

Copy link
Author

Choose a reason for hiding this comment

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

Agree, ideally rate package would return a typed error here

Copy link
Author

Choose a reason for hiding this comment

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

Added a test.

Also, this doesn't feel like the right spot for this logic.

Do you have a suggestion what would be a better place?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe somewhere up the call stack. I'm not a maintainer of this project, just a user, so this may be fine with maintainers.

}
return false
}
6 changes: 6 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,12 @@ 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",
},
}

for tn, tc := range testCases {
Expand Down