Improve the lister function documentation

In particular, document that ListAllByNamespace delegates to ListAll
if no namespace is specified.

Signed-off-by: Stephen Kitt <skitt@redhat.com>

Kubernetes-commit: 54e899317ef46e3b70827cacee244717022db0ad
This commit is contained in:
Stephen Kitt 2024-04-19 17:58:02 +02:00 committed by Kubernetes Publisher
parent 9d701d3504
commit 841e997e33

View File

@ -30,7 +30,7 @@ import (
// AppendFunc is used to add a matching item to whatever list the caller is using // AppendFunc is used to add a matching item to whatever list the caller is using
type AppendFunc func(interface{}) type AppendFunc func(interface{})
// ListAll calls appendFn with each value retrieved from store which matches the selector. // ListAll lists items in the store matching the given selector, calling appendFn on each one.
func ListAll(store Store, selector labels.Selector, appendFn AppendFunc) error { func ListAll(store Store, selector labels.Selector, appendFn AppendFunc) error {
selectAll := selector.Empty() selectAll := selector.Empty()
for _, m := range store.List() { for _, m := range store.List() {
@ -51,7 +51,9 @@ func ListAll(store Store, selector labels.Selector, appendFn AppendFunc) error {
return nil return nil
} }
// ListAllByNamespace used to list items belongs to namespace from Indexer. // ListAllByNamespace lists items in the given namespace in the store matching the given selector,
// calling appendFn on each one.
// If a blank namespace (NamespaceAll) is specified, this delegates to ListAll().
func ListAllByNamespace(indexer Indexer, namespace string, selector labels.Selector, appendFn AppendFunc) error { func ListAllByNamespace(indexer Indexer, namespace string, selector labels.Selector, appendFn AppendFunc) error {
if namespace == metav1.NamespaceAll { if namespace == metav1.NamespaceAll {
return ListAll(indexer, selector, appendFn) return ListAll(indexer, selector, appendFn)