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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Client: use passed in Cache.DisableFor option #2303

Merged
merged 1 commit into from
May 5, 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
4 changes: 2 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ func newClient(config *rest.Config, options Options) (*client, error) {

// Load uncached GVKs.
c.cacheUnstructured = options.Cache.Unstructured
uncachedGVKs := map[schema.GroupVersionKind]struct{}{}
c.uncachedGVKs = map[schema.GroupVersionKind]struct{}{}
for _, obj := range options.Cache.DisableFor {
gvk, err := c.GroupVersionKindFor(obj)
if err != nil {
return nil, err
}
uncachedGVKs[gvk] = struct{}{}
c.uncachedGVKs[gvk] = struct{}{}
}
return c, nil
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
Expect(cl.List(ctx, &appsv1.DeploymentList{})).To(Succeed())
Expect(cache.Called).To(Equal(2))
})

It("should not use the provided reader cache if provided, on get and list for uncached GVKs", func() {
cache := &fakeReader{}
cl, err := client.New(cfg, client.Options{Cache: &client.CacheOptions{Reader: cache, DisableFor: []client.Object{&corev1.Namespace{}}}})
Expect(err).NotTo(HaveOccurred())
Expect(cl).NotTo(BeNil())
Expect(cl.Get(ctx, client.ObjectKey{Name: "default"}, &corev1.Namespace{})).To(Succeed())
Expect(cl.List(ctx, &corev1.NamespaceList{})).To(Succeed())
Expect(cache.Called).To(Equal(0))
})
})

Describe("Create", func() {
Expand Down