mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-27 15:39:39 +00:00
Server side implementation of paging for etcd3
Add a feature gate in the apiserver to control whether paging can be used. Add controls to the storage factory that allow it to be disabled per resource. Use a JSON encoded continuation token that can be versioned. Create a 410 error if the continuation token is expired. Adds GetContinue() to ListMeta. Kubernetes-commit: 8952a0cb722b77459cf2701632a30f5b264f5aba
This commit is contained in:
parent
2b76a1826e
commit
6adf847055
@ -30,14 +30,20 @@ import (
|
|||||||
|
|
||||||
const defaultPageSize = 500
|
const defaultPageSize = 500
|
||||||
|
|
||||||
|
// ListPageFunc returns a list object for the given list options.
|
||||||
type ListPageFunc func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error)
|
type ListPageFunc func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error)
|
||||||
|
|
||||||
|
// SimplePageFunc adapts a context-less list function into one that accepts a context.
|
||||||
func SimplePageFunc(fn func(opts metav1.ListOptions) (runtime.Object, error)) ListPageFunc {
|
func SimplePageFunc(fn func(opts metav1.ListOptions) (runtime.Object, error)) ListPageFunc {
|
||||||
return func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
|
return func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
|
||||||
return fn(opts)
|
return fn(opts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListPager assists client code in breaking large list queries into multiple
|
||||||
|
// smaller chunks of PageSize or smaller. PageFn is expected to accept a
|
||||||
|
// metav1.ListOptions that supports paging and return a list. The pager does
|
||||||
|
// not alter the field or label selectors on the initial options list.
|
||||||
type ListPager struct {
|
type ListPager struct {
|
||||||
PageSize int64
|
PageSize int64
|
||||||
PageFn ListPageFunc
|
PageFn ListPageFunc
|
||||||
@ -45,6 +51,8 @@ type ListPager struct {
|
|||||||
FullListIfExpired bool
|
FullListIfExpired bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates a new pager from the provided pager function using the default
|
||||||
|
// options.
|
||||||
func New(fn ListPageFunc) *ListPager {
|
func New(fn ListPageFunc) *ListPager {
|
||||||
return &ListPager{
|
return &ListPager{
|
||||||
PageSize: defaultPageSize,
|
PageSize: defaultPageSize,
|
||||||
@ -53,6 +61,9 @@ func New(fn ListPageFunc) *ListPager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List returns a single list object, but attempts to retrieve smaller chunks from the
|
||||||
|
// server to reduce the impact on the server. If the chunk attempt fails, it will load
|
||||||
|
// the full list instead.
|
||||||
func (p *ListPager) List(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) {
|
func (p *ListPager) List(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) {
|
||||||
if options.Limit == 0 {
|
if options.Limit == 0 {
|
||||||
options.Limit = p.PageSize
|
options.Limit = p.PageSize
|
||||||
|
Loading…
Reference in New Issue
Block a user