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

Support API chunking #283

Closed
cben opened this issue Jan 10, 2018 · 3 comments
Closed

Support API chunking #283

cben opened this issue Jan 10, 2018 · 3 comments

Comments

@cben
Copy link
Collaborator

cben commented Jan 10, 2018

k8s recently finally got response chunking (kinda pagination, of a consistent snapshot at single resourceVersion!):
kubernetes/community#896 => https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-chunking.md
kubernetes/enhancements#365
https://kubernetes.io/docs/reference/using-api/api-concepts/

This has similar benefits to streaming parsing (#254) for peak RAM on client, but also reduces peak RAM on server, and avoids some annoyances like client timing out while server builds response.
Would be great in at some point in kubeclient.
Do we still also want streaming parsing? Don't have an opinion yet.

First I want to figure out if same block-based API as in #254 is also good for chunking? Or do we need something lower-level that gives user more control?

@cben
Copy link
Collaborator Author

cben commented Jan 10, 2018

Seems this is supported starting with kubernetes 1.8 API.

@cben
Copy link
Collaborator Author

cben commented Aug 23, 2018

2 open questions:

  1. How should whole-collection metadata, notably resource_version, be returned?
    Process JSON Body of ListObjects using streaming json parser #254 in current form first yields each item, at the end returns a hash with resourceVersion & kind keys.
    For streaming parse this was motivated by not assuming k8s always puts items key last in the JSON.
    For chunking, we do have metadata in each chunk, and parse whole chunk at a time, so could also expose it earlier.

  2. what to do with 410 Gone mid-iteration?

    Like a watch operation, a continue token will expire after a short amount of time (by default 5 minutes) and return a 410 Gone if more results cannot be returned. In this case, the client will need to start from the beginning or omit the limit parameter.
    -- api-concepts

    How should this scenario be handled by kubeclient? Raise exception? Does this preclude access to whole-collection metadata?

Perhaps we need a 2-step interface like watch:

iter = client.iter_pods
puts "can access #{iter.resourceVersion} early?"
begin
  iter.each { |pod| ... }
  puts "can access #{iter.resourceVersion} at the end"
rescue
  puts "can still access #{iter.resourceVersion} if lost it mid-way!"
end

robust but awkward :-(
would prefer simpler 1-step client.get_pods { ... } if possible.

agrare added a commit to agrare/kubeclient that referenced this issue Oct 17, 2018
Implement API chunking support as specified in
https://kubernetes.io/docs/reference/using-api/api-concepts/#retrieving-large-results-sets-in-chunks

Add limit and continue as parameters to get_entities and get_entities
and add continue as an optional attribute (default to nil) to
EntityList.

Fixes: ManageIQ#283
@agrare
Copy link
Member

agrare commented Oct 17, 2018

@cben I took a crack at this over in #356
Not sure that it is the interface that you're looking for but it works well, see full example usage in https://github.com/agrare/openshift-collector/blob/wip_chunk_kubernetes_api_responses/lib/openshift/collector.rb#L85-L113

agrare added a commit to agrare/kubeclient that referenced this issue Oct 17, 2018
Implement API chunking support as specified in
https://kubernetes.io/docs/reference/using-api/api-concepts/#retrieving-large-results-sets-in-chunks

Add limit and continue as parameters to get_entities and watch_entities
and add continue as an optional attribute (default to nil) to
EntityList.

Fixes: ManageIQ#283
agrare added a commit to agrare/kubeclient that referenced this issue Oct 18, 2018
Implement API chunking support as specified in
https://kubernetes.io/docs/reference/using-api/api-concepts/#retrieving-large-results-sets-in-chunks

Add limit and continue as parameters to get_entities add
continue as an optional attribute (default to nil) to
EntityList.

Fixes: ManageIQ#283
agrare added a commit to agrare/kubeclient that referenced this issue Oct 29, 2018
Implement API chunking support as specified in
https://kubernetes.io/docs/reference/using-api/api-concepts/#retrieving-large-results-sets-in-chunks

Add limit and continue as parameters to get_entities add
continue as an optional attribute (default to nil) to
EntityList.

Fixes: ManageIQ#283
@cben cben closed this as completed in #356 Nov 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants