Skip to content

Commit 3f886b9

Browse files
committed
Client: use passed in Cache.DisableFor option
1 parent 07a8152 commit 3f886b9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pkg/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ func newClient(config *rest.Config, options Options) (*client, error) {
191191

192192
// Load uncached GVKs.
193193
c.cacheUnstructured = options.Cache.Unstructured
194-
uncachedGVKs := map[schema.GroupVersionKind]struct{}{}
194+
c.uncachedGVKs = map[schema.GroupVersionKind]struct{}{}
195195
for _, obj := range options.Cache.DisableFor {
196196
gvk, err := c.GroupVersionKindFor(obj)
197197
if err != nil {
198198
return nil, err
199199
}
200-
uncachedGVKs[gvk] = struct{}{}
200+
c.uncachedGVKs[gvk] = struct{}{}
201201
}
202202
return c, nil
203203
}

pkg/client/client_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
277277
Expect(cl.List(ctx, &appsv1.DeploymentList{})).To(Succeed())
278278
Expect(cache.Called).To(Equal(2))
279279
})
280+
281+
It("should not use the provided reader cache if provided, on get and list for uncached GVKs", func() {
282+
cache := &fakeReader{}
283+
cl, err := client.New(cfg, client.Options{Cache: &client.CacheOptions{Reader: cache, DisableFor: []client.Object{&corev1.Namespace{}}}})
284+
Expect(err).NotTo(HaveOccurred())
285+
Expect(cl).NotTo(BeNil())
286+
Expect(cl.Get(ctx, client.ObjectKey{Name: "default"}, &corev1.Namespace{})).To(Succeed())
287+
Expect(cl.List(ctx, &corev1.NamespaceList{})).To(Succeed())
288+
Expect(cache.Called).To(Equal(0))
289+
})
280290
})
281291

282292
Describe("Create", func() {

0 commit comments

Comments
 (0)