Skip to content

Commit d2ab642

Browse files
committed
Fix EachListItemWithAlloc and use it
1 parent 62d82f9 commit d2ab642

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pkg/controller/sharder/reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (r *Reconciler) resyncResource(
166166

167167
list := &metav1.PartialObjectMetadataList{}
168168
list.SetGroupVersionKind(gvks[0])
169-
err = pager.New(r.Reader).EachListItem(ctx, list,
169+
err = pager.New(r.Reader).EachListItemWithAlloc(ctx, list,
170170
func(obj client.Object) error {
171171
if !namespaces.Has(obj.GetNamespace()) {
172172
return nil

pkg/utils/pager/pager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type ListPager struct {
6868
// ListPager.PageBufferSize chunks buffered concurrently in the background.
6969
//
7070
// If items passed to fn are retained for different durations, and you want to avoid
71-
// retaining the whole slice returned by p.PageFn as long as any item is referenced,
71+
// retaining the whole slice returned by p.Reader.List as long as any item is referenced,
7272
// use EachListItemWithAlloc instead.
7373
func (p *ListPager) EachListItem(ctx context.Context, list client.ObjectList, fn func(obj client.Object) error, opts ...client.ListOption) error {
7474
return p.eachListChunkBuffered(ctx, list, func(list client.ObjectList) error {
@@ -78,13 +78,13 @@ func (p *ListPager) EachListItem(ctx context.Context, list client.ObjectList, fn
7878
}, opts...)
7979
}
8080

81-
// EachListItemWithAlloc works like EachListItem, but avoids retaining references to the items slice returned by p.PageFn.
82-
// It does this by making a shallow copy of non-pointer items in the slice returned by p.PageFn.
81+
// EachListItemWithAlloc works like EachListItem, but avoids retaining references to the items slice returned by p.Reader.List.
82+
// It does this by making a shallow copy of non-pointer items in the slice returned by p.Reader.List.
8383
//
8484
// If the items passed to fn are not retained, or are retained for the same duration, use EachListItem instead for memory efficiency.
8585
func (p *ListPager) EachListItemWithAlloc(ctx context.Context, list client.ObjectList, fn func(obj client.Object) error, opts ...client.ListOption) error {
8686
return p.eachListChunkBuffered(ctx, list, func(list client.ObjectList) error {
87-
return meta.EachListItem(list, func(obj runtime.Object) error {
87+
return meta.EachListItemWithAlloc(list, func(obj runtime.Object) error {
8888
return fn(obj.(client.Object))
8989
})
9090
}, opts...)

0 commit comments

Comments
 (0)