pager

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResultStream

func ResultStream(ctx context.Context) chan runtime.Object

func WithResultStream

func WithResultStream(parent context.Context, ch chan runtime.Object) context.Context

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.

If items passed to fn are retained for different durations, and you want to avoid retaining the whole slice returned by p.PageFn as long as any item is referenced, use EachListItemWithAlloc instead.

func (*ListPager) EachListItemWithAlloc

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

EachListItemWithAlloc works like EachListItem, but avoids retaining references to the items slice returned by p.PageFn. It does this by making a shallow copy of non-pointer items in the slice returned by p.PageFn.

If the items passed to fn are not retained, or are retained for the same duration, use EachListItem instead for memory efficiency.

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.

If items in the returned list are retained for different durations, and you want to avoid retaining the whole slice returned by p.PageFn as long as any item is referenced, use ListWithAlloc instead.

func (*ListPager) ListWithAlloc

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

ListWithAlloc works like List, but avoids retaining references to the items slice returned by p.PageFn. It does this by making a shallow copy of non-pointer items in the slice returned by p.PageFn.

If the items in the returned list are not retained, or are retained for the same duration, use List instead for memory efficiency.

Jump to

Keyboard shortcuts

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