Skip to content

Commit

Permalink
clarify comments, reword
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri committed Jul 19, 2023
1 parent e61ecb8 commit 5e4945c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
5 changes: 3 additions & 2 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
})

Expand Down
7 changes: 3 additions & 4 deletions pkg/cache/informer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5e4945c

Please sign in to comment.