Proposal: enhance xxxLister to use index

18 views
Skip to first unread message

adam zhou

unread,
Apr 1, 2021, 12:21:56 PM4/1/21
to Kubernetes developer/contributor discussion
Hi everyone.

 What's the proposal

 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)
  ... 
}

   pr related: #99767

What problem it solves.

Here is one of the cases I encountered:  code
  1.  I have to find some of the pods by label selector.
  2. 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
  1. All finding things should use xxxLister. Using multiple way increase complexity.
  2. the index is a powerful feature. Should be encouraged to use.
  3. 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
  1. looking for other cases that can benefit from it. (need this too, use lister and index)
  2. open discussion on this, maybe it is not needed we found after discussion here.
  if anyone has any thought,  please.

thanks




Daniel Smith

unread,
Apr 1, 2021, 12:46:30 PM4/1/21
to adam zhou, K8s API Machinery SIG, Kubernetes developer/contributor discussion
+K8s API Machinery SIG owns the Lister code.

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/726f958c-99c6-4c04-ba40-acb18a8693a5n%40googlegroups.com.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages