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

⚠️ DynamicRestMapper: return NoMatchError when resource doesn't exist #1151

Merged

Conversation

timebertt
Copy link
Contributor

@timebertt timebertt commented Sep 7, 2020

Fixes #1120

This PR fixes the DynamicRESTMapper's behaviour when it is rate limited:
Instead of returning ErrRateLimited, it now directly returns the meta.NoKindMatchError / meta.NoResourceMatchError given by the underlying mapper. This way, existing controller code using meta.IsNoMatchError works as expected also in the case when the RESTMapper is rate limited.

This is breaking ⚠️ because:

  • the DynamicRESTMapper does now return a NoKindMatchError/NoResourceMatchError instead of ErrRateLimited in case the resource doesn't exist and it was rate limited
  • ErrRateLimited and DelayIfRateLimited are removed, as they aren't needed anymore

Additional notes:
The given rate limit can now be seen as an agreement on how often the mapper should refresh its cache (at max). So if the limit is reached, it basically means, we have refreshed often enough (met the contract) and we can safely rely on the cache and directly return the error.

I improved the tests a bit along the way, to ensure all cases are properly tested and made them a bit faster.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 7, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @timebertt. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 7, 2020
@timebertt
Copy link
Contributor Author

/assign @droot

@timebertt
Copy link
Contributor Author

/assign @DirectXMan12

Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

like the general concept. Left a comment re: your question.

pkg/client/apiutil/dynamicrestmapper.go Show resolved Hide resolved
@timebertt
Copy link
Contributor Author

@DirectXMan12 WDYT about my comment?

@alvaroaleman
Copy link
Member

@timebertt can we retitle the PR to clarify the problem its solving rather than implementation details (something like "DynamicRestMapper: Return NoMatchError when resource type doesn't exist") ?

@timebertt
Copy link
Contributor Author

/title DynamicRestMapper: return NoMatchError when resource doesn't exist

Any thought on the compatability story, @alvaroaleman?

@timebertt timebertt changed the title ⚠️ DynamicRESTMapper: return NoMatchErrors when rate limited ⚠️ DynamicRestMapper: return NoMatchError when resource doesn't exist Sep 17, 2020
@timebertt
Copy link
Contributor Author

Pinging @alvaroaleman @DirectXMan12
Any additional feedback on this PR?

@timebertt timebertt changed the title ⚠️ DynamicRestMapper: return NoMatchError when resource doesn't exist 🐛 DynamicRestMapper: return NoMatchError when resource doesn't exist Sep 27, 2020
@timebertt
Copy link
Contributor Author

I made this PR backwards-compatible by deprecating ErrRateLimited and associated funcs instead of just removing it.

Can we now proceed with the PR?
/assign @DirectXMan12 @alvaroaleman

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/ok-to-test

pkg/client/apiutil/dynamicrestmapper.go Outdated Show resolved Hide resolved
pkg/client/apiutil/dynamicrestmapper.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 28, 2020
@vincepri
Copy link
Member

/milestone v0.7.x

@k8s-ci-robot k8s-ci-robot added this to the v0.7.x milestone Sep 28, 2020
Expect(callWithOther()).To(Succeed())
Expect(callWithTarget()).To(Succeed())
})
Expect(callWithOther()).To(beNoMatchError())
Copy link
Member

Choose a reason for hiding this comment

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

Why does this fail on the first attempt now and only works on the second?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was also failing on the first attempt before (see L62) as the secondGVK is not present by default (see L33)
I just moved down the first callWithOther and added count to ensure, that the RESTMapper really tries to rediscover for the call with the unknown resource.

pkg/client/apiutil/dynamicrestmapper.go Outdated Show resolved Hide resolved
@timebertt timebertt changed the title 🐛 DynamicRestMapper: return NoMatchError when resource doesn't exist ⚠️ DynamicRestMapper: return NoMatchError when resource doesn't exist Sep 30, 2020
@timebertt
Copy link
Contributor Author

/retest

@k8s-ci-robot
Copy link
Contributor

@timebertt: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-controller-runtime-apidiff-master b8e24db link /test pull-controller-runtime-apidiff-master

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@timebertt
Copy link
Contributor Author

@alvaroaleman @vincepri Thanks for your feedback. Makes sense to me.
I removed ErrRateLimited and DelayIfRateLimited, marked the PR/commit as ⚠️ and added a note to the PR description.
PTAL :)

@timebertt
Copy link
Contributor Author

How can I make pull-controller-runtime-apidiff-master happy?

@alvaroaleman
Copy link
Member

How can I make pull-controller-runtime-apidiff-master happy?

You can't, because its a breaking change. The job is optional though.

/lgtm
/approve

Thanks for your work!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 30, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, timebertt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 30, 2020
@k8s-ci-robot k8s-ci-robot merged commit 749cc0c into kubernetes-sigs:master Sep 30, 2020
@timebertt timebertt deleted the fix/dynamic-rest-mapper branch September 30, 2020 14:20
@timebertt
Copy link
Contributor Author

How can I make pull-controller-runtime-apidiff-master happy?

You can't, because its a breaking change. The job is optional though.

Ah, got it.
Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic RESTMapper returns ErrRateLimited instead of expected NoKindMatchError
6 participants