From e2aab093aa0df38e49ebab85414b7c569fdf23e1 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sat, 4 Jun 2016 22:46:54 -0700 Subject: [PATCH] cacher.go: remove NewCacher func NewCacher is a wrapper of NewCacherFromConfig. NewCacher understands how to create a key func from scopeStrategy. However, it is not the responsibility of cacher. So we should remove this function, and construct the config in its caller, which should understand scopeStrategy. --- .../generic/registry/storage_factory.go | 23 +++++++++++-- pkg/storage/cacher.go | 32 ------------------- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/pkg/registry/generic/registry/storage_factory.go b/pkg/registry/generic/registry/storage_factory.go index f1c265113bf..4a9c845ccc4 100644 --- a/pkg/registry/generic/registry/storage_factory.go +++ b/pkg/registry/generic/registry/storage_factory.go @@ -31,7 +31,24 @@ func StorageWithCacher( resourcePrefix string, scopeStrategy rest.NamespaceScopedStrategy, newListFunc func() runtime.Object) storage.Interface { - return storage.NewCacher( - storageInterface, capacity, etcdstorage.APIObjectVersioner{}, - objectType, resourcePrefix, scopeStrategy, newListFunc) + + config := storage.CacherConfig{ + CacheCapacity: capacity, + Storage: storageInterface, + Versioner: etcdstorage.APIObjectVersioner{}, + Type: objectType, + ResourcePrefix: resourcePrefix, + NewListFunc: newListFunc, + } + if scopeStrategy.NamespaceScoped() { + config.KeyFunc = func(obj runtime.Object) (string, error) { + return storage.NamespaceKeyFunc(resourcePrefix, obj) + } + } else { + config.KeyFunc = func(obj runtime.Object) (string, error) { + return storage.NoNamespaceKeyFunc(resourcePrefix, obj) + } + } + + return storage.NewCacherFromConfig(config) } diff --git a/pkg/storage/cacher.go b/pkg/storage/cacher.go index e7b4d63e2f0..0444a2d09b5 100644 --- a/pkg/storage/cacher.go +++ b/pkg/storage/cacher.go @@ -28,7 +28,6 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/errors" "k8s.io/kubernetes/pkg/api/meta" - "k8s.io/kubernetes/pkg/api/rest" "k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/client/cache" "k8s.io/kubernetes/pkg/conversion" @@ -111,37 +110,6 @@ type Cacher struct { stopWg sync.WaitGroup } -// Create a new Cacher responsible from service WATCH and LIST requests from its -// internal cache and updating its cache in the background based on the given -// configuration. -func NewCacher( - storage Interface, - capacity int, - versioner Versioner, - objectType runtime.Object, - resourcePrefix string, - scopeStrategy rest.NamespaceScopedStrategy, - newListFunc func() runtime.Object) Interface { - config := CacherConfig{ - CacheCapacity: capacity, - Storage: storage, - Versioner: versioner, - Type: objectType, - ResourcePrefix: resourcePrefix, - NewListFunc: newListFunc, - } - if scopeStrategy.NamespaceScoped() { - config.KeyFunc = func(obj runtime.Object) (string, error) { - return NamespaceKeyFunc(resourcePrefix, obj) - } - } else { - config.KeyFunc = func(obj runtime.Object) (string, error) { - return NoNamespaceKeyFunc(resourcePrefix, obj) - } - } - return NewCacherFromConfig(config) -} - // Create a new Cacher responsible from service WATCH and LIST requests from its // internal cache and updating its cache in the background based on the given // configuration.