const defaultPageSize … const defaultPageBufferSize … type ListPageFunc … // SimplePageFunc adapts a context-less list function into one that accepts a context. func SimplePageFunc(fn func(opts metav1.ListOptions) (runtime.Object, error)) ListPageFunc { … } type 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 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. 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 (p *ListPager) List(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. func (p *ListPager) ListWithAlloc(ctx context.Context, options metav1.ListOptions) (runtime.Object, bool, error) { … } func (p *ListPager) list(ctx context.Context, options metav1.ListOptions, allocNew bool) (runtime.Object, bool, 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 (p *ListPager) EachListItem(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 (p *ListPager) EachListItemWithAlloc(ctx context.Context, options metav1.ListOptions, fn func(obj runtime.Object) error) error { … } // eachListChunkBuffered fetches runtimeObject list chunks using this ListPager and invokes fn on // each list chunk. 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. // // Up to ListPager.PageBufferSize chunks are buffered concurrently in the background. func (p *ListPager) eachListChunkBuffered(ctx context.Context, options metav1.ListOptions, fn func(obj runtime.Object) error) error { … } // eachListChunk fetches runtimeObject list chunks using this ListPager and invokes fn on each list // chunk. 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. func (p *ListPager) eachListChunk(ctx context.Context, options metav1.ListOptions, fn func(obj runtime.Object) error) error { … }