client-go: support Shutdown() for metadata and dynamic informers (#114434)

* client-go: support `Shutdown()` for metadata and dynamic informers

Followup to https://github.com/kubernetes/kubernetes/pull/112200,
specifically
https://github.com/kubernetes/kubernetes/pull/112200#issuecomment-1344812038.

* add comments

* Defer lock

Kubernetes-commit: b99fe0d5b9896dd3fe9a2c1bc3b399a18ad080d2
This commit is contained in:
John Howard
2023-02-28 23:09:17 -08:00
committed by Kubernetes Publisher
parent 9ea785f819
commit 089d04441d
4 changed files with 93 additions and 2 deletions

View File

@@ -24,9 +24,28 @@ import (
// DynamicSharedInformerFactory provides access to a shared informer and lister for dynamic client
type DynamicSharedInformerFactory interface {
// Start initializes all requested informers. They are handled in goroutines
// which run until the stop channel gets closed.
Start(stopCh <-chan struct{})
// ForResource gives generic access to a shared informer of the matching type.
ForResource(gvr schema.GroupVersionResource) informers.GenericInformer
// WaitForCacheSync blocks until all started informers' caches were synced
// or the stop channel gets closed.
WaitForCacheSync(stopCh <-chan struct{}) map[schema.GroupVersionResource]bool
// Shutdown marks a factory as shutting down. At that point no new
// informers can be started anymore and Start will return without
// doing anything.
//
// In addition, Shutdown blocks until all goroutines have terminated. For that
// to happen, the close channel(s) that they were started with must be closed,
// either before Shutdown gets called or while it is waiting.
//
// Shutdown may be called multiple times, even concurrently. All such calls will
// block until all goroutines have terminated.
Shutdown()
}
// TweakListOptionsFunc defines the signature of a helper function