-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[WIP] ✨ Add support for implicit paging in un/structured clients #1358
Conversation
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.
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. |
Welcome @nimrodshn! |
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 Once the patch is verified, the new status will be reflected by the 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: nimrodshn 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 |
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. |
@coderanger I tend to agree. I guess the idea is to hide the use of |
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. |
@coderanger I had implemented it this way b/c I thought that is what reported in #532 - how do you view it? |
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. |
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. |
@coderanger Interesting.. I will try and tackle those ideas. Indeed this implementation is fairly naive. |
974f336
to
d3492ab
Compare
@coderanger Please re-tal; specifically at the implementation at the cc: @cben |
d3492ab
to
b445caa
Compare
@@ -23,6 +23,11 @@ import ( | |||
"k8s.io/apimachinery/pkg/selection" | |||
) | |||
|
|||
const ( | |||
// DefaultPageLimit represents the default limit used when specifyinh the 'Page' ListOption. | |||
DefaultPageLimit = 100 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err != nil { | ||
return err | ||
} | ||
allItems = append(allItems, items...) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
})
There was a problem hiding this comment.
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 :)
ea71907
to
370a5b9
Compare
370a5b9
to
7b60362
Compare
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
@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. |
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 theContinue
curser token with a callback to be used by the user.Open Questions:
ListPages
be part of theReader
interface?@ncdc @DirectXMan12 @vincepri @cben PTAL.