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

⚠️ Return an error if the continue list option is set for the cache reader #2439

Merged
merged 1 commit into from Aug 10, 2023

Conversation

shuheiktgw
Copy link
Contributor

@shuheiktgw shuheiktgw commented Aug 5, 2023

Hi, currently the cache reader ignores the continue option. This behavior could lead to a hard-to-find bug when a user mistakenly tries to paginate with the limit and continue option by the cache client. I faced the problem, and that was quite hard to debug since the limit option works correctly and I always received the first page only. I believe it is more user-friendly if we just return an error when a user mistakenly set the option instead of ignoring it silently. Thanks for your review!

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 5, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @shuheiktgw!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @shuheiktgw. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 5, 2023
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 5, 2023
@shuheiktgw
Copy link
Contributor Author

/ok-to-test

@k8s-ci-robot
Copy link
Contributor

@shuheiktgw: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/ok-to-test

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.

@gjkim42
Copy link
Member

gjkim42 commented Aug 7, 2023

/ok-to-test

@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 Aug 7, 2023
@gjkim42
Copy link
Member

gjkim42 commented Aug 7, 2023

This behavior could lead to a hard-to-find bug when a user mistakenly tries to paginate with the limit and continue option by the cache client. I faced the problem, and that was quite hard to debug since the limit option works correctly and I always received the first page only.

I believe that I faced the same issue here.

@czeslavo
Copy link

czeslavo commented Aug 7, 2023

I have one concern: a typical flow of using pagination is you set Limit to your page size and leave Continue empty in your first List call. This fix wouldn't catch that someone is trying to use CacheReader with pagination as Continue would be empty anyway.

As CacheReader.List accepts ListOptions with both Limit and Continue, claiming de facto it implements the client.Reader interface, wouldn't it make sense to simulate the continuation on its side? If we don't do that, it's always on the caller's side to know what kind of a client is being used and account for continuations not working for some of them, which is not a perfect situation. I'd expect the interface to be implemented consistently despite the implementation details.

@alvaroaleman
Copy link
Member

As CacheReader.List accepts ListOptions with both Limit and Continue, claiming de facto it implements the client.Reader interface, wouldn't it make sense to simulate the continuation on its side?

Thats on the callers side anyways, because the two are not identical, they just expose an identical interface. You for example have to know that if you get data from cache it might be stale and deal with that properly.

@@ -111,6 +111,10 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
listOpts := client.ListOptions{}
listOpts.ApplyOptions(opts)

if listOpts.Continue != "" {
Copy link
Member

Choose a reason for hiding this comment

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

I agree with this change, however it is technically breaking because using this before would not do anything, now it returns an error. Could you update the title accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I've updated the title 🙂

@czeslavo
Copy link

czeslavo commented Aug 7, 2023

Thats on the callers side anyways, because the two are not identical, they just expose an identical interface. You for example have to know that if you get data from cache it might be stale and deal with that properly.

If that's expected to not implement some options it technically accepts, could we make sure that these intentional gaps are properly documented?

@shuheiktgw shuheiktgw changed the title ✨ Return an error if the continue list option is set for the cache reader ⚠️ Return an error if the continue list option is set for the cache reader Aug 7, 2023
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 10, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 Aug 10, 2023
@k8s-ci-robot k8s-ci-robot merged commit 5aa6a71 into kubernetes-sigs:main Aug 10, 2023
15 checks passed
@shuheiktgw shuheiktgw deleted the fail_cache_continue branch August 11, 2023 00:55
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/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants