Merge pull request #26854 from xiang90/cacher

Automatic merge from submit-queue

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.
pull/6/head
k8s-merge-robot 2016-06-25 11:10:06 -07:00 committed by GitHub
commit 00b5b548d6
2 changed files with 20 additions and 35 deletions

View File

@ -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)
}

View File

@ -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.