Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ Return an error if the continue list option is set for the cache reader #2439

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this change, however it is technically breaking because using this before would not do anything, now it returns an error. Could you update the title accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I've updated the title 🙂

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