Skip to content

Commit

Permalink
Client: use passed in Cache.DisableFor option
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed May 5, 2023
1 parent 07a8152 commit 3f886b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/client/client.go
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
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

0 comments on commit 3f886b9

Please sign in to comment.