From 4eb89249bd7da52fe9335050ff3d7e8d470f20ae Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Thu, 18 Jul 2019 06:45:48 -0700 Subject: [PATCH] Rename TriggerPublisherFunc as IndexerFunc Kubernetes-commit: 6e98aab26e4fb867a6d8b4342937823cf1597d89 --- pkg/registry/generic/options.go | 2 +- .../generic/registry/storage_factory.go | 22 +++++++++---------- pkg/registry/generic/storage_decorator.go | 4 ++-- pkg/storage/cacher/cacher.go | 20 ++++++++--------- pkg/storage/interfaces.go | 10 ++++----- 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/pkg/registry/generic/options.go b/pkg/registry/generic/options.go index fb9adba1a..907928a35 100644 --- a/pkg/registry/generic/options.go +++ b/pkg/registry/generic/options.go @@ -47,6 +47,6 @@ type RESTOptionsGetter interface { // StoreOptions is set of configuration options used to complete generic registries. type StoreOptions struct { RESTOptions RESTOptionsGetter - TriggerFunc storage.TriggerPublisherFuncs + TriggerFunc storage.IndexerFuncs AttrFunc storage.AttrFunc } diff --git a/pkg/registry/generic/registry/storage_factory.go b/pkg/registry/generic/registry/storage_factory.go index acefc2386..7fb785a5b 100644 --- a/pkg/registry/generic/registry/storage_factory.go +++ b/pkg/registry/generic/registry/storage_factory.go @@ -39,7 +39,7 @@ func StorageWithCacher(capacity int) generic.StorageDecorator { newFunc func() runtime.Object, newListFunc func() runtime.Object, getAttrsFunc storage.AttrFunc, - triggerFuncs storage.TriggerPublisherFuncs) (storage.Interface, factory.DestroyFunc, error) { + triggerFuncs storage.IndexerFuncs) (storage.Interface, factory.DestroyFunc, error) { s, d, err := generic.NewRawStorage(storageConfig) if err != nil { @@ -56,16 +56,16 @@ func StorageWithCacher(capacity int) generic.StorageDecorator { // TODO: we would change this later to make storage always have cacher and hide low level KV layer inside. // Currently it has two layers of same storage interface -- cacher and low level kv. cacherConfig := cacherstorage.Config{ - CacheCapacity: capacity, - Storage: s, - Versioner: etcd3.APIObjectVersioner{}, - ResourcePrefix: resourcePrefix, - KeyFunc: keyFunc, - NewFunc: newFunc, - NewListFunc: newListFunc, - GetAttrsFunc: getAttrsFunc, - TriggerPublisherFuncs: triggerFuncs, - Codec: storageConfig.Codec, + CacheCapacity: capacity, + Storage: s, + Versioner: etcd3.APIObjectVersioner{}, + ResourcePrefix: resourcePrefix, + KeyFunc: keyFunc, + NewFunc: newFunc, + NewListFunc: newListFunc, + GetAttrsFunc: getAttrsFunc, + IndexerFuncs: triggerFuncs, + Codec: storageConfig.Codec, } cacher, err := cacherstorage.NewCacherFromConfig(cacherConfig) if err != nil { diff --git a/pkg/registry/generic/storage_decorator.go b/pkg/registry/generic/storage_decorator.go index 1c553413e..993f21200 100644 --- a/pkg/registry/generic/storage_decorator.go +++ b/pkg/registry/generic/storage_decorator.go @@ -32,7 +32,7 @@ type StorageDecorator func( newFunc func() runtime.Object, newListFunc func() runtime.Object, getAttrsFunc storage.AttrFunc, - trigger storage.TriggerPublisherFuncs) (storage.Interface, factory.DestroyFunc, error) + trigger storage.IndexerFuncs) (storage.Interface, factory.DestroyFunc, error) // UndecoratedStorage returns the given a new storage from the given config // without any decoration. @@ -43,7 +43,7 @@ func UndecoratedStorage( newFunc func() runtime.Object, newListFunc func() runtime.Object, getAttrsFunc storage.AttrFunc, - trigger storage.TriggerPublisherFuncs) (storage.Interface, factory.DestroyFunc, error) { + trigger storage.IndexerFuncs) (storage.Interface, factory.DestroyFunc, error) { return NewRawStorage(config) } diff --git a/pkg/storage/cacher/cacher.go b/pkg/storage/cacher/cacher.go index 2b701084d..2fa49efaf 100644 --- a/pkg/storage/cacher/cacher.go +++ b/pkg/storage/cacher/cacher.go @@ -88,9 +88,9 @@ type Config struct { // GetAttrsFunc is used to get object labels, fields GetAttrsFunc func(runtime.Object) (label labels.Set, field fields.Set, err error) - // TriggerPublisherFuncs is used for optimizing amount of watchers that + // IndexerFuncs is used for optimizing amount of watchers that // needs to process an incoming event. - TriggerPublisherFuncs storage.TriggerPublisherFuncs + IndexerFuncs storage.IndexerFuncs // NewFunc is a function that creates new empty object storing a object of type Type. NewFunc func() runtime.Object @@ -211,7 +211,7 @@ type filterWithAttrsFunc func(key string, l labels.Set, f fields.Set) bool type indexedTriggerFunc struct { indexName string - triggerFunc storage.TriggerPublisherFunc + indexerFunc storage.IndexerFunc } // Cacher is responsible for serving WATCH and LIST requests for a given @@ -306,17 +306,17 @@ func NewCacherFromConfig(config Config) (*Cacher, error) { } var indexedTrigger *indexedTriggerFunc - if config.TriggerPublisherFuncs != nil { + if config.IndexerFuncs != nil { // For now, we don't support multiple trigger functions defined // for a given resource. - if len(config.TriggerPublisherFuncs) > 1 { - return nil, fmt.Errorf("cacher %s doesn't support more than one TriggerPublisherFunc: ", reflect.TypeOf(obj).String()) + if len(config.IndexerFuncs) > 1 { + return nil, fmt.Errorf("cacher %s doesn't support more than one IndexerFunc: ", reflect.TypeOf(obj).String()) } - for key, value := range config.TriggerPublisherFuncs { + for key, value := range config.IndexerFuncs { if value != nil { indexedTrigger = &indexedTriggerFunc{ indexName: key, - triggerFunc: value, + indexerFunc: value, } } } @@ -742,11 +742,11 @@ func (c *Cacher) triggerValues(event *watchCacheEvent) ([]string, bool) { } result := make([]string, 0, 2) - result = append(result, c.indexedTrigger.triggerFunc(event.Object)) + result = append(result, c.indexedTrigger.indexerFunc(event.Object)) if event.PrevObject == nil { return result, true } - prevTriggerValue := c.indexedTrigger.triggerFunc(event.PrevObject) + prevTriggerValue := c.indexedTrigger.indexerFunc(event.PrevObject) if result[0] != prevTriggerValue { result = append(result, prevTriggerValue) } diff --git a/pkg/storage/interfaces.go b/pkg/storage/interfaces.go index c850b2484..f5d3b3ea7 100644 --- a/pkg/storage/interfaces.go +++ b/pkg/storage/interfaces.go @@ -73,15 +73,13 @@ type ResponseMeta struct { ResourceVersion uint64 } -// TriggerPublisherFunc is a function that for a given object computes +// IndexerFunc is a function that for a given object computes // for a particular . -// TODO(wojtek-t): Rename to IndexerFunc? -type TriggerPublisherFunc func(obj runtime.Object) string +type IndexerFunc func(obj runtime.Object) string -// TriggerPublisherFuncs is a mapping from to function that +// IndexerFuncs is a mapping from to function that // for a given object computes . -// TODO(wojtek-t): Rename to IndexerFuncs? -type TriggerPublisherFuncs map[string]TriggerPublisherFunc +type IndexerFuncs map[string]IndexerFunc // Everything accepts all objects. var Everything = SelectionPredicate{