pager

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListPager

type ListPager struct {
	Reader client.Reader

	// PageSize is the maximum number of objects to retrieve in individual list calls.
	// If a client.Limit option is passed, the pager uses the option's value instead.
	PageSize int64
	// Number of pages to buffer in EachListItem and EachListItemWithAlloc.
	PageBufferSize int32
}

ListPager assists client code in breaking large list queries into multiple smaller chunks of PageSize or smaller. The pager does not alter any fields on the initial options list except Continue. It is implemented like client-go's pager but uses a controller-runtime client, see https://github.com/kubernetes/client-go/blob/release-1.28/tools/pager/pager.go. Exception: this ListPager also fixes the `specifying resource version is not allowed when using continue` error in EachListItem and EachListItemWithAlloc.

func New

func New(reader client.Reader) *ListPager

New creates a new pager from the provided reader using the default options.

func (*ListPager) EachListItem

func (p *ListPager) EachListItem(ctx context.Context, list client.ObjectList, fn func(obj client.Object) error, opts ...client.ListOption) 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, list client.ObjectList, fn func(obj client.Object) error, opts ...client.ListOption) 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.

Jump to

Keyboard shortcuts

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