diff --git a/pkg/client/client.go b/pkg/client/client.go index 49a398b3cc..21067b6f8f 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -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 } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index e2f53008e9..bd368e7a3f 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -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() {