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

[WIP] ✨ Add support for implicit paging in un/structured clients #1358

Conversation

nimrodshn
Copy link

@nimrodshn nimrodshn commented Jan 24, 2021

What this does?

Following #341 this patch adds implicit paging to the un/structured clients. Fixes #532.

Thoughts about the API:

This patch opts for adding a new Method called ListPages: This method lists large data in "chunks" using the Continue curser token with a callback to be used by the user.

Open Questions:

  • Should ListPages be part of the Reader interface?

@ncdc @DirectXMan12 @vincepri @cben PTAL.

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please sign in with your organization's credentials at https://identity.linuxfoundation.org/projects/cncf to be authorized.
  • If you have done the above and are still having issues with the CLA being reported as unsigned, please log a ticket with the Linux Foundation Helpdesk: https://support.linuxfoundation.org/
  • Should you encounter any issues with the Linux Foundation Helpdesk, send a message to the backup e-mail support address at: [email protected]

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jan 24, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @nimrodshn!

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 @nimrodshn. 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 Jan 24, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: nimrodshn
To complete the pull request process, please assign vincepri after the PR has been reviewed.
You can assign the PR to them by writing /assign @vincepri in a comment when ready.

The full list of commands accepted by this bot can be found 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 24, 2021
@coderanger
Copy link
Contributor

This feels weird to me. What is the use case for this? Generally when a pagination cursor exists, not using it will lead to lots of weird race condition bugs when the object set changes between requests.

@nimrodshn
Copy link
Author

@coderanger I tend to agree. I guess the idea is to hide the use of Continue from the user. Albeit the user can simply use Continue and view pages of data as it is now. Please refer to #532 for more information.

@coderanger
Copy link
Contributor

I don't think this is what #532 was referring to. In what situation would you ever want to ask for "page 4 of the results" when you have no idea what that will even contain? The only time I could see someone doing that is in error when they want to get all items via pagination, but using this code they would get all those bugs I mentioned, which is why a pagination cursor is returned.

@nimrodshn
Copy link
Author

@coderanger I had implemented it this way b/c I thought that is what reported in #532 - how do you view it?

@coderanger
Copy link
Contributor

That List() would automatically check if a continue token was returned, and (give or take an option flag) automatically fetch the next page and combine it with the the results you already have, and repeat until no more data is returned. When accessing a huge list of objects that change frequently (e.g. all Pods) this can spread out the load on the API server, trading increased effective latency to remove the massive IO spike that could disrupt API server stability.

@coderanger
Copy link
Contributor

Or there's the option @vincepri mentioned of doing a similar looped get with an iterator function callback so you never have to hold the full list of objects in memory at once. Both could be useful in different situations.

@nimrodshn
Copy link
Author

nimrodshn commented Jan 24, 2021

@coderanger Interesting.. I will try and tackle those ideas. Indeed this implementation is fairly naive.

@nimrodshn nimrodshn changed the title :sperkles: Add support for implicit paging in un/structured clients [WIP] :sperkles: Add support for implicit paging in un/structured clients Jan 24, 2021
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 24, 2021
@nimrodshn nimrodshn changed the title [WIP] :sperkles: Add support for implicit paging in un/structured clients [WIP] ✨ Add support for implicit paging in un/structured clients Jan 25, 2021
@nimrodshn nimrodshn force-pushed the implicit_implementation_of_paging branch from 974f336 to d3492ab Compare January 26, 2021 08:01
@nimrodshn
Copy link
Author

nimrodshn commented Jan 26, 2021

@coderanger Please re-tal; specifically at the implementation at the typed_client.go - is this the direction you had in mind? what about the callback do you think it is necessary? Should we add the ListPages method to the Reader interface?

cc: @cben

@nimrodshn nimrodshn force-pushed the implicit_implementation_of_paging branch from d3492ab to b445caa Compare January 26, 2021 08:10
@@ -23,6 +23,11 @@ import (
"k8s.io/apimachinery/pkg/selection"
)

const (
// DefaultPageLimit represents the default limit used when specifyinh the 'Page' ListOption.
DefaultPageLimit = 100
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably needs a better name since it's not the default for List() too.

Copy link
Author

@nimrodshn nimrodshn Jan 27, 2021

Choose a reason for hiding this comment

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

@vincepri @cben Any suggestions?

if err != nil {
return err
}
allItems = append(allItems, items...)
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want both a callback function and a huge list return, we should pick one pattern or the other (or move them to separate functions/options). The reason to use a visitor callback function is to avoid keeping the whole list in memory. I think it would be more Go-like to just do the callback style probably, ExtractList() requires a lot of runtime reflect magic since there is no unified API for accessing list items. But having both available could be convenient.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vincepri Do you have opinions on which API to support (or both)?

Copy link
Author

@nimrodshn nimrodshn Jan 27, 2021

Choose a reason for hiding this comment

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

Gotcha. 👍

@coderanger Actoually thinking about it - if the user would like to accumulate the result she can simply use the same ExtractList inside the callback.

Copy link
Author

@nimrodshn nimrodshn Jan 27, 2021

Choose a reason for hiding this comment

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

That is, she can pass something like this:

out := &corev1.Pods{}
allItems := make([]runtime.Object, 0)
cl.ListPages(ctx, out,  func(obj client.ObjectList) error {
    items, err := apimeta.ExtractList(interimResult)
    if err != nil {
        return err
    }
    allItems = append(allItems, items...)
    return nil
})

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, or more likely cast it to the correct type and skip needing ExtractList :)

@nimrodshn nimrodshn force-pushed the implicit_implementation_of_paging branch 2 times, most recently from ea71907 to 370a5b9 Compare January 27, 2021 07:58
@nimrodshn nimrodshn force-pushed the implicit_implementation_of_paging branch from 370a5b9 to 7b60362 Compare January 27, 2021 08:26
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 27, 2021
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 27, 2021
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 23, 2021
@k8s-ci-robot
Copy link
Contributor

@nimrodshn: PR needs rebase.

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.

@nimrodshn nimrodshn closed this Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.

Add pagination support to clients
4 participants