Merge pull request #80300 from tedyu/idx-trigger

Rename TriggerPublisherFunc as IndexerFunc
This commit is contained in:
Kubernetes Prow Robot 2019-07-18 13:24:33 -07:00 committed by GitHub
commit 477304cdbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 33 deletions

View File

@ -93,7 +93,7 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, kubeletClientConfig client
options := &generic.StoreOptions{ options := &generic.StoreOptions{
RESTOptions: optsGetter, RESTOptions: optsGetter,
AttrFunc: node.GetAttrs, AttrFunc: node.GetAttrs,
TriggerFunc: map[string]storage.TriggerPublisherFunc{"metadata.name": node.NodeNameTriggerFunc}, TriggerFunc: map[string]storage.IndexerFunc{"metadata.name": node.NodeNameTriggerFunc},
} }
if err := store.CompleteWithOptions(options); err != nil { if err := store.CompleteWithOptions(options); err != nil {
return nil, err return nil, err

View File

@ -81,7 +81,7 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, k client.ConnectionInfoGet
options := &generic.StoreOptions{ options := &generic.StoreOptions{
RESTOptions: optsGetter, RESTOptions: optsGetter,
AttrFunc: pod.GetAttrs, AttrFunc: pod.GetAttrs,
TriggerFunc: map[string]storage.TriggerPublisherFunc{"spec.nodeName": pod.NodeNameTriggerFunc}, TriggerFunc: map[string]storage.IndexerFunc{"spec.nodeName": pod.NodeNameTriggerFunc},
} }
if err := store.CompleteWithOptions(options); err != nil { if err := store.CompleteWithOptions(options); err != nil {
panic(err) // TODO: Propagate error up panic(err) // TODO: Propagate error up

View File

@ -50,7 +50,7 @@ func NewREST(optsGetter generic.RESTOptionsGetter) *REST {
options := &generic.StoreOptions{ options := &generic.StoreOptions{
RESTOptions: optsGetter, RESTOptions: optsGetter,
AttrFunc: secret.GetAttrs, AttrFunc: secret.GetAttrs,
TriggerFunc: map[string]storage.TriggerPublisherFunc{"metadata.name": secret.SecretNameTriggerFunc}, TriggerFunc: map[string]storage.IndexerFunc{"metadata.name": secret.SecretNameTriggerFunc},
} }
if err := store.CompleteWithOptions(options); err != nil { if err := store.CompleteWithOptions(options); err != nil {
panic(err) // TODO: Propagate error up panic(err) // TODO: Propagate error up

View File

@ -47,6 +47,6 @@ type RESTOptionsGetter interface {
// StoreOptions is set of configuration options used to complete generic registries. // StoreOptions is set of configuration options used to complete generic registries.
type StoreOptions struct { type StoreOptions struct {
RESTOptions RESTOptionsGetter RESTOptions RESTOptionsGetter
TriggerFunc storage.TriggerPublisherFuncs TriggerFunc storage.IndexerFuncs
AttrFunc storage.AttrFunc AttrFunc storage.AttrFunc
} }

View File

@ -39,7 +39,7 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
newFunc func() runtime.Object, newFunc func() runtime.Object,
newListFunc func() runtime.Object, newListFunc func() runtime.Object,
getAttrsFunc storage.AttrFunc, 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) s, d, err := generic.NewRawStorage(storageConfig)
if err != nil { 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. // 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. // Currently it has two layers of same storage interface -- cacher and low level kv.
cacherConfig := cacherstorage.Config{ cacherConfig := cacherstorage.Config{
CacheCapacity: capacity, CacheCapacity: capacity,
Storage: s, Storage: s,
Versioner: etcd3.APIObjectVersioner{}, Versioner: etcd3.APIObjectVersioner{},
ResourcePrefix: resourcePrefix, ResourcePrefix: resourcePrefix,
KeyFunc: keyFunc, KeyFunc: keyFunc,
NewFunc: newFunc, NewFunc: newFunc,
NewListFunc: newListFunc, NewListFunc: newListFunc,
GetAttrsFunc: getAttrsFunc, GetAttrsFunc: getAttrsFunc,
TriggerPublisherFuncs: triggerFuncs, IndexerFuncs: triggerFuncs,
Codec: storageConfig.Codec, Codec: storageConfig.Codec,
} }
cacher, err := cacherstorage.NewCacherFromConfig(cacherConfig) cacher, err := cacherstorage.NewCacherFromConfig(cacherConfig)
if err != nil { if err != nil {

View File

@ -32,7 +32,7 @@ type StorageDecorator func(
newFunc func() runtime.Object, newFunc func() runtime.Object,
newListFunc func() runtime.Object, newListFunc func() runtime.Object,
getAttrsFunc storage.AttrFunc, 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 // UndecoratedStorage returns the given a new storage from the given config
// without any decoration. // without any decoration.
@ -43,7 +43,7 @@ func UndecoratedStorage(
newFunc func() runtime.Object, newFunc func() runtime.Object,
newListFunc func() runtime.Object, newListFunc func() runtime.Object,
getAttrsFunc storage.AttrFunc, getAttrsFunc storage.AttrFunc,
trigger storage.TriggerPublisherFuncs) (storage.Interface, factory.DestroyFunc, error) { trigger storage.IndexerFuncs) (storage.Interface, factory.DestroyFunc, error) {
return NewRawStorage(config) return NewRawStorage(config)
} }

View File

@ -88,9 +88,9 @@ type Config struct {
// GetAttrsFunc is used to get object labels, fields // GetAttrsFunc is used to get object labels, fields
GetAttrsFunc func(runtime.Object) (label labels.Set, field fields.Set, err error) 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. // 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 is a function that creates new empty object storing a object of type Type.
NewFunc func() runtime.Object NewFunc func() runtime.Object
@ -211,7 +211,7 @@ type filterWithAttrsFunc func(key string, l labels.Set, f fields.Set) bool
type indexedTriggerFunc struct { type indexedTriggerFunc struct {
indexName string indexName string
triggerFunc storage.TriggerPublisherFunc indexerFunc storage.IndexerFunc
} }
// Cacher is responsible for serving WATCH and LIST requests for a given // 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 var indexedTrigger *indexedTriggerFunc
if config.TriggerPublisherFuncs != nil { if config.IndexerFuncs != nil {
// For now, we don't support multiple trigger functions defined // For now, we don't support multiple trigger functions defined
// for a given resource. // for a given resource.
if len(config.TriggerPublisherFuncs) > 1 { if len(config.IndexerFuncs) > 1 {
return nil, fmt.Errorf("cacher %s doesn't support more than one TriggerPublisherFunc: ", reflect.TypeOf(obj).String()) 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 { if value != nil {
indexedTrigger = &indexedTriggerFunc{ indexedTrigger = &indexedTriggerFunc{
indexName: key, indexName: key,
triggerFunc: value, indexerFunc: value,
} }
} }
} }
@ -742,11 +742,11 @@ func (c *Cacher) triggerValues(event *watchCacheEvent) ([]string, bool) {
} }
result := make([]string, 0, 2) 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 { if event.PrevObject == nil {
return result, true return result, true
} }
prevTriggerValue := c.indexedTrigger.triggerFunc(event.PrevObject) prevTriggerValue := c.indexedTrigger.indexerFunc(event.PrevObject)
if result[0] != prevTriggerValue { if result[0] != prevTriggerValue {
result = append(result, prevTriggerValue) result = append(result, prevTriggerValue)
} }

View File

@ -73,15 +73,13 @@ type ResponseMeta struct {
ResourceVersion uint64 ResourceVersion uint64
} }
// TriggerPublisherFunc is a function that for a given object computes // IndexerFunc is a function that for a given object computes
// <value of an index> for a particular <index>. // <value of an index> for a particular <index>.
// TODO(wojtek-t): Rename to IndexerFunc? type IndexerFunc func(obj runtime.Object) string
type TriggerPublisherFunc func(obj runtime.Object) string
// TriggerPublisherFuncs is a mapping from <index name> to function that // IndexerFuncs is a mapping from <index name> to function that
// for a given object computes <value for that index>. // for a given object computes <value for that index>.
// TODO(wojtek-t): Rename to IndexerFuncs? type IndexerFuncs map[string]IndexerFunc
type TriggerPublisherFuncs map[string]TriggerPublisherFunc
// Everything accepts all objects. // Everything accepts all objects.
var Everything = SelectionPredicate{ var Everything = SelectionPredicate{