Skip to content

Commit

Permalink
Rename cache.Options.Resync to SyncPeriod
Browse files Browse the repository at this point in the history
  • Loading branch information
ary1992 committed Jun 23, 2023
1 parent d895168 commit 41c6e5d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions pkg/client/kubernetes/cache/single_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ var _ = Describe("SingleObject", func() {
ctx context.Context
ctrl *gomock.Controller

obj *corev1.Secret
gvk = corev1.SchemeGroupVersion.WithKind("Secret")
key client.ObjectKey
resync = pointer.Duration(time.Second)
obj *corev1.Secret
gvk = corev1.SchemeGroupVersion.WithKind("Secret")
key client.ObjectKey
syncPeriod = pointer.Duration(time.Second)

mockCache *mockcache.MockCache
singleObjectCache cache.Cache
Expand Down Expand Up @@ -74,12 +74,12 @@ var _ = Describe("SingleObject", func() {
Expect(opts.Namespaces).To(ConsistOf(obj.Namespace))
Expect(opts.DefaultFieldSelector).To(Equal(fields.SelectorFromSet(fields.Set{"metadata.name": obj.Name})))
Expect(opts.ByObject).To(BeNil())
Expect(opts.Resync).To(Equal(resync))
Expect(opts.SyncPeriod).To(Equal(syncPeriod))
return mockCache, nil
}
clock = testclock.NewFakeClock(time.Now())

singleObjectCache = NewSingleObject(logr.Discard(), nil, newCacheFunc, cache.Options{Resync: resync}, gvk, clock, maxIdleTime, 50*time.Millisecond)
singleObjectCache = NewSingleObject(logr.Discard(), nil, newCacheFunc, cache.Options{SyncPeriod: syncPeriod}, gvk, clock, maxIdleTime, 50*time.Millisecond)

var cancel context.CancelFunc
parentCtx, cancel = context.WithCancel(context.Background())
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ func newClientSet(conf *Config) (Interface, error) {

if runtimeCache == nil {
runtimeCache, err = conf.newRuntimeCache(conf.restConfig, cache.Options{
Scheme: conf.clientOptions.Scheme,
Mapper: conf.clientOptions.Mapper,
Resync: conf.cacheResync,
Scheme: conf.clientOptions.Scheme,
Mapper: conf.clientOptions.Mapper,
SyncPeriod: conf.cacheSyncPeriod,
})
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/kubernetes/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Config struct {
newRuntimeCache cache.NewCacheFunc
clientOptions client.Options
restConfig *rest.Config
cacheResync *time.Duration
cacheSyncPeriod *time.Duration
disableCache bool
uncachedObjects []client.Object
allowedUserFields []string
Expand Down Expand Up @@ -108,10 +108,10 @@ func WithClientOptions(opt client.Options) ConfigFunc {
}
}

// WithCacheResyncPeriod returns a ConfigFunc that set the client's cache's resync period to the given duration.
func WithCacheResyncPeriod(resync time.Duration) ConfigFunc {
// WithCacheSyncPeriod returns a ConfigFunc that set the client's cache's sync period to the given duration.
func WithCacheResyncPeriod(sync time.Duration) ConfigFunc {
return func(config *Config) error {
config.cacheResync = &resync
config.cacheSyncPeriod = &sync
return nil
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/kubernetes/runtime_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

const (
defaultCacheResyncPeriod = 6 * time.Hour
defaultCacheSyncPeriod = 6 * time.Hour
)

// NewRuntimeCache creates a new cache.Cache with the given config and options. It can be used
Expand All @@ -47,8 +47,8 @@ func NewRuntimeCache(config *rest.Config, options cache.Options) (cache.Cache, e
}

func setCacheOptionsDefaults(options *cache.Options) error {
if options.Resync == nil {
options.Resync = pointer.Duration(defaultCacheResyncPeriod)
if options.SyncPeriod == nil {
options.SyncPeriod = pointer.Duration(defaultCacheSyncPeriod)
}

return nil
Expand Down

0 comments on commit 41c6e5d

Please sign in to comment.