Hi everyone.
Add interface to xxxLister, to use an arbitrary indexer.
something like:
// corev1/pod.go
// List lists all Pods use specific index
func (s podIndexLister) List(indexName, key string, selector labels.Selector) (ret []*v1.Pod, err error) {
err = cache.ListByIndex(s.indexer, indexName, key, selector, func(m interface{}) {
ret = append(ret, m.(*v1.Pod))
})
return ret, err
}
// cache package
// ListByIndex used to list items using specific index
func ListByIndex(indexer Indexer, name, key string, selector labels.Selector, appendFn AppendFunc) error{
items, err := indexer.ByIndex(name, key)
...
}
What problem it solves.
Here is one of the cases I encountered:
code- I have to find some of the pods by label selector.
- use index can accelerate the finding, use ns is slow (hundreds of them in one ns).
So, to find them I have to use informer.Indexer, but sometimes I use lister to get a specific pod.
those two obj both have to pass to a package, so it can use them to do its own business logic, like finding something.
Now with the new Lister, I can use lister to list any obj I want with high effectiveness.
Why it should be added to lister
- All finding things should use xxxLister. Using multiple way increase complexity.
- the index is a powerful feature. Should be encouraged to use.
- xxxLister can only make use of the namespace index, which is not enough.
so, add an interface that can not only complete xxxLister but also encourage people to use the powerful index as well.
and, we never get confused when to use informer or index or lister.
What I need now
- looking for other cases that can benefit from it. (need this too, use lister and index)
- open discussion on this, maybe it is not needed we found after discussion here.
if anyone has any thought, please.
thanks