diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index f4e7152c26..160fdcfc78 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -168,8 +168,9 @@ type Options struct { UnsafeDisableDeepCopy *bool // FailOnUnknownResource configures the cache to return a ErrResourceNotCached error when a user - // requests a resource the cache is not configured to hold. This error is distinct from an - // errors.NotFound. + // requests, using Get() and List(), a resource the cache does not already have an informer for. + // + // This error is distinct from an errors.NotFound. // // Defaults to false, which means that the cache will start a new informer // for every new requested resource. diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index ce66ace332..3fd9d38339 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -120,8 +120,8 @@ var _ = Describe("Informer Cache", func() { CacheTest(cache.New, cache.Options{}) }) -var _ = Describe("Informer Cache with miss policy = fail", func() { - CacheTestMissPolicyFail(cache.New, cache.Options{FailOnUnknownResource: true}) +var _ = Describe("Informer Cache with FailOnUnknownResource", func() { + CacheTestFailOnUnknownResource(cache.New, cache.Options{FailOnUnknownResource: true}) }) var _ = Describe("Multi-Namespace Informer Cache", func() { @@ -421,7 +421,7 @@ var _ = Describe("Cache with selectors", func() { }) }) -func CacheTestMissPolicyFail(createCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error), opts cache.Options) { +func CacheTestFailOnUnknownResource(createCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error), opts cache.Options) { Describe("Cache test with UnknownResourcePolicy = fail", func() { var ( informerCache cache.Cache @@ -456,7 +456,6 @@ func CacheTestMissPolicyFail(createCacheFunc func(config *rest.Config, opts cach It("should not be able to list objects that haven't been watched previously", func() { By("listing all services in the cluster") listObj := &corev1.ServiceList{} - fmt.Printf("%#v\n", informerCache.List(context.Background(), listObj)) Expect(errors.As(informerCache.List(context.Background(), listObj), &errNotCached)).To(BeTrue()) }) diff --git a/pkg/cache/informer_cache.go b/pkg/cache/informer_cache.go index 836a38ade3..f530e576da 100644 --- a/pkg/cache/informer_cache.go +++ b/pkg/cache/informer_cache.go @@ -154,16 +154,15 @@ func (ic *informerCache) GetInformer(ctx context.Context, obj client.Object) (In } func (ic *informerCache) getInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, obj runtime.Object) (bool, *internal.Cache, error) { - switch { - case ic.failOnUnknown: + if ic.failOnUnknown { cache, started, ok := ic.Informers.Peek(gvk, obj) if !ok { return false, nil, &errors.ErrResourceNotCached{GVK: gvk} } return started, cache, nil - default: - return ic.Informers.Get(ctx, gvk, obj) } + + return ic.Informers.Get(ctx, gvk, obj) } // NeedLeaderElection implements the LeaderElectionRunnable interface diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index f52101d3c2..177f6de798 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -25,7 +25,6 @@ import ( "sync/atomic" "time" - "github.com/davecgh/go-spew/spew" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" @@ -3943,7 +3942,6 @@ type fakeReader struct { } func (f *fakeReader) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - spew.Dump("key") f.Called++ return nil }