-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2755 from panslava/rename-informer
Rename projectinformer to filteredinformer
- Loading branch information
Showing
12 changed files
with
432 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package filteredinformer | ||
|
||
import ( | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
// providerConfigFilteredCache implements cache.Store and cache.Indexer with provider config filtering. | ||
type providerConfigFilteredCache struct { | ||
cache.Indexer | ||
providerConfigName string | ||
} | ||
|
||
func (pc *providerConfigFilteredCache) ByIndex(indexName, indexedValue string) ([]interface{}, error) { | ||
items, err := pc.Indexer.ByIndex(indexName, indexedValue) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return providerConfigFilteredList(items, pc.providerConfigName), nil | ||
} | ||
|
||
func (pc *providerConfigFilteredCache) Index(indexName string, obj interface{}) ([]interface{}, error) { | ||
items, err := pc.Indexer.Index(indexName, obj) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return providerConfigFilteredList(items, pc.providerConfigName), nil | ||
} | ||
|
||
func (pc *providerConfigFilteredCache) List() []interface{} { | ||
return providerConfigFilteredList(pc.Indexer.List(), pc.providerConfigName) | ||
} | ||
|
||
func (pc *providerConfigFilteredCache) ListKeys() []string { | ||
items := pc.List() | ||
var keys []string | ||
for _, item := range items { | ||
if key, err := cache.MetaNamespaceKeyFunc(item); err == nil { | ||
keys = append(keys, key) | ||
} | ||
} | ||
return keys | ||
} | ||
|
||
func (pc *providerConfigFilteredCache) Get(obj interface{}) (item interface{}, exists bool, err error) { | ||
key, err := cache.MetaNamespaceKeyFunc(obj) | ||
if err != nil { | ||
return nil, false, err | ||
} | ||
return pc.GetByKey(key) | ||
} | ||
|
||
func (pc *providerConfigFilteredCache) GetByKey(key string) (item interface{}, exists bool, err error) { | ||
item, exists, err = pc.Indexer.GetByKey(key) | ||
if !exists || err != nil { | ||
return nil, exists, err | ||
} | ||
if isObjectInProviderConfig(item, pc.providerConfigName) { | ||
return item, true, nil | ||
} | ||
return nil, false, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package filteredinformer | ||
|
||
import ( | ||
"time" | ||
|
||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
// ProviderConfigFilteredInformer wraps a SharedIndexInformer to provide a ProviderConfig filtered view. | ||
type ProviderConfigFilteredInformer struct { | ||
cache.SharedIndexInformer | ||
providerConfigName string | ||
} | ||
|
||
// NewProviderConfigFilteredInformer creates a new ProviderConfigFilteredInformer. | ||
func NewProviderConfigFilteredInformer(informer cache.SharedIndexInformer, providerConfigName string) cache.SharedIndexInformer { | ||
return &ProviderConfigFilteredInformer{ | ||
SharedIndexInformer: informer, | ||
providerConfigName: providerConfigName, | ||
} | ||
} | ||
|
||
// AddEventHandler adds an event handler that only processes events for the specified ProviderConfig. | ||
func (i *ProviderConfigFilteredInformer) AddEventHandler(handler cache.ResourceEventHandler) (cache.ResourceEventHandlerRegistration, error) { | ||
return i.SharedIndexInformer.AddEventHandler( | ||
cache.FilteringResourceEventHandler{ | ||
FilterFunc: i.providerConfigFilter, | ||
Handler: handler, | ||
}, | ||
) | ||
} | ||
|
||
// AddEventHandlerWithResyncPeriod adds an event handler with resync period. | ||
func (i *ProviderConfigFilteredInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, resyncPeriod time.Duration) (cache.ResourceEventHandlerRegistration, error) { | ||
return i.SharedIndexInformer.AddEventHandlerWithResyncPeriod( | ||
cache.FilteringResourceEventHandler{ | ||
FilterFunc: i.providerConfigFilter, | ||
Handler: handler, | ||
}, | ||
resyncPeriod, | ||
) | ||
} | ||
|
||
// providerConfigFilter filters objects based on the provider config. | ||
func (i *ProviderConfigFilteredInformer) providerConfigFilter(obj interface{}) bool { | ||
return isObjectInProviderConfig(obj, i.providerConfigName) | ||
} | ||
|
||
func (i *ProviderConfigFilteredInformer) GetStore() cache.Store { | ||
return &providerConfigFilteredCache{ | ||
Indexer: i.SharedIndexInformer.GetIndexer(), | ||
providerConfigName: i.providerConfigName, | ||
} | ||
} | ||
|
||
func (i *ProviderConfigFilteredInformer) GetIndexer() cache.Indexer { | ||
return &providerConfigFilteredCache{ | ||
Indexer: i.SharedIndexInformer.GetIndexer(), | ||
providerConfigName: i.providerConfigName, | ||
} | ||
} |
Oops, something went wrong.