mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #80300 from tedyu/idx-trigger
Rename TriggerPublisherFunc as IndexerFunc
This commit is contained in:
commit
477304cdbd
@ -93,7 +93,7 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, kubeletClientConfig client
|
||||
options := &generic.StoreOptions{
|
||||
RESTOptions: optsGetter,
|
||||
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 {
|
||||
return nil, err
|
||||
|
@ -81,7 +81,7 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, k client.ConnectionInfoGet
|
||||
options := &generic.StoreOptions{
|
||||
RESTOptions: optsGetter,
|
||||
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 {
|
||||
panic(err) // TODO: Propagate error up
|
||||
|
@ -50,7 +50,7 @@ func NewREST(optsGetter generic.RESTOptionsGetter) *REST {
|
||||
options := &generic.StoreOptions{
|
||||
RESTOptions: optsGetter,
|
||||
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 {
|
||||
panic(err) // TODO: Propagate error up
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
// <value of an index> for a particular <index>.
|
||||
// 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 <index name> to function that
|
||||
// IndexerFuncs is a mapping from <index name> to function that
|
||||
// for a given object computes <value for that index>.
|
||||
// TODO(wojtek-t): Rename to IndexerFuncs?
|
||||
type TriggerPublisherFuncs map[string]TriggerPublisherFunc
|
||||
type IndexerFuncs map[string]IndexerFunc
|
||||
|
||||
// Everything accepts all objects.
|
||||
var Everything = SelectionPredicate{
|
||||
|
Loading…
Reference in New Issue
Block a user