pager

package
v0.0.0-...-d88c8b5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListPageFunc

type ListPageFunc func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error)

ListPageFunc returns a list object for the given list options.

func SimplePageFunc

func SimplePageFunc(fn func(opts metav1.ListOptions) (runtime.Object, error)) ListPageFunc

SimplePageFunc adapts a context-less list function into one that accepts a context.

type ListPager

type ListPager struct {
	PageSize int64
	PageFn   ListPageFunc

	FullListIfExpired bool

	// Number of pages to buffer
	PageBufferSize int32
}

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.

func New

func New(fn ListPageFunc) *ListPager

New creates a new pager from the provided pager function using the default options. It will fall back to a full list if an expiration error is encountered as a last resort.

func (*ListPager) EachListItem

func (p *ListPager) EachListItem(ctx context.Context, options metav1.ListOptions, fn func(obj runtime.Object) error) error

EachListItem fetches runtime.Object items using this ListPager and invokes fn on each item. If fn returns an error, processing stops and that error is returned. If fn does not return an error, any error encountered while retrieving the list from the server is returned. If the context cancels or times out, the context error is returned. Since the list is retrieved in paginated chunks, an "Expired" error (metav1.StatusReasonExpired) may be returned if the pagination list requests exceed the expiration limit of the apiserver being called.

Items are retrieved in chunks from the server to reduce the impact on the server with up to ListPager.PageBufferSize chunks buffered concurrently in the background.

func (*ListPager) List

func (p *ListPager) List(ctx context.Context, options metav1.ListOptions) (runtime.Object, bool, error)

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. The Limit field on options, if unset, will default to the page size.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL