Skip to content

Commit 3600637

Browse files
committed
Return error when object limit exceeded for cached list calls
Since the cache does not implement strongly consistent paginated list calls, if the Limit option is set and the number of items listed exceeds this limit, there is no way for the caller to get a complete list of objects, so return an error here to notify the caller.
1 parent aea2e32 commit 3600637

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pkg/cache/internal/cache_reader.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,17 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
139139
labelSel = listOpts.LabelSelector
140140
}
141141

142+
// Since the cache does not implement strongly consistent paginated list
143+
// calls, if the Limit option is set and the number of items listed exceeds
144+
// this limit, there is no way for the caller to get a complete list of
145+
// objects, so return an error here to notify the caller.
142146
limitSet := listOpts.Limit > 0
147+
if limitSet && int64(len(objs)) > listOpts.Limit {
148+
return fmt.Errorf("object limit exceeded but paginated list is not supported by the cache")
149+
}
143150

144151
runtimeObjs := make([]runtime.Object, 0, len(objs))
145152
for _, item := range objs {
146-
// if the Limit option is set and the number of items
147-
// listed exceeds this limit, then stop reading.
148-
if limitSet && int64(len(runtimeObjs)) >= listOpts.Limit {
149-
break
150-
}
151153
obj, isObj := item.(runtime.Object)
152154
if !isObj {
153155
return fmt.Errorf("cache contained %T, which is not an Object", item)

0 commit comments

Comments
 (0)