mirror of
https://github.com/kubernetes/sample-controller.git
synced 2026-04-12 00:00:26 +08:00
Generate informers with InformerName support
Kubernetes-commit: 1fec293a1d9fc53e0e3f1a6a3fe6f8970110c1a7
This commit is contained in:
committed by
Kubernetes Publisher
parent
5628993de5
commit
c7b42271a6
@@ -43,6 +43,7 @@ type sharedInformerFactory struct {
|
||||
defaultResync time.Duration
|
||||
customResync map[reflect.Type]time.Duration
|
||||
transform cache.TransformFunc
|
||||
informerName *cache.InformerName
|
||||
|
||||
informers map[reflect.Type]cache.SharedIndexInformer
|
||||
// startedInformers is used for tracking which informers have been started.
|
||||
@@ -89,6 +90,21 @@ func WithTransform(transform cache.TransformFunc) SharedInformerOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithInformerName sets the InformerName for informer identity used in metrics.
|
||||
// The InformerName must be created via cache.NewInformerName() at startup,
|
||||
// which validates global uniqueness. Each informer type will register its
|
||||
// GVR under this name.
|
||||
func WithInformerName(informerName *cache.InformerName) SharedInformerOption {
|
||||
return func(factory *sharedInformerFactory) *sharedInformerFactory {
|
||||
factory.informerName = informerName
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
func (f *sharedInformerFactory) InformerName() *cache.InformerName {
|
||||
return f.informerName
|
||||
}
|
||||
|
||||
// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
|
||||
func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
|
||||
return NewSharedInformerFactoryWithOptions(client, defaultResync)
|
||||
@@ -153,6 +169,7 @@ func (f *sharedInformerFactory) Shutdown() {
|
||||
|
||||
// Will return immediately if there is nothing to wait for.
|
||||
f.wg.Wait()
|
||||
f.informerName.Release()
|
||||
}
|
||||
|
||||
func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool {
|
||||
|
||||
Reference in New Issue
Block a user