Skip to content

Commit

Permalink
Merge pull request #2439 from shuheiktgw/fail_cache_continue
Browse files Browse the repository at this point in the history
⚠️ Return an error if the continue list option is set for the cache reader
  • Loading branch information
k8s-ci-robot committed Aug 10, 2023
2 parents 5bf44d2 + 674087d commit 5aa6a71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Expect(informerCache.List(context.Background(), listObj, labelOpt, limitOpt)).To(Succeed())
Expect(listObj.Items).Should(HaveLen(1))
})

It("should return an error if the continue list options is set", func() {
listObj := &corev1.PodList{}
continueOpt := client.Continue("token")
By("verifying that an error is returned")
err := informerCache.List(context.Background(), listObj, continueOpt)
Expect(err).To(HaveOccurred())
})
})

Context("with unstructured objects", func() {
Expand Down Expand Up @@ -1002,6 +1010,13 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Expect(nodeList.Items).NotTo(BeEmpty())
Expect(len(nodeList.Items)).To(BeEquivalentTo(1))
})
It("should return an error if the continue list options is set", func() {
podList := &unstructured.Unstructured{}
continueOpt := client.Continue("token")
By("verifying that an error is returned")
err := informerCache.List(context.Background(), podList, continueOpt)
Expect(err).To(HaveOccurred())
})
})
Context("with metadata-only objects", func() {
It("should be able to list objects that haven't been watched previously", func() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cache/internal/cache_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
listOpts := client.ListOptions{}
listOpts.ApplyOptions(opts)

if listOpts.Continue != "" {
return fmt.Errorf("continue list option is not supported by the cache")
}

switch {
case listOpts.FieldSelector != nil:
// TODO(directxman12): support more complicated field selectors by
Expand Down

0 comments on commit 5aa6a71

Please sign in to comment.