From 96386809339faee1169d163749cb4b7d354bec1e Mon Sep 17 00:00:00 2001 From: Richa Banker Date: Thu, 5 Feb 2026 11:45:38 -0800 Subject: [PATCH] Wire InformerName through SharedIndexInformer --- .../k8s.io/client-go/tools/cache/controller.go | 18 ++++++++++++++---- ...reflector_data_consistency_detector_test.go | 2 +- .../client-go/tools/cache/shared_informer.go | 18 +++++++++++++++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/staging/src/k8s.io/client-go/tools/cache/controller.go b/staging/src/k8s.io/client-go/tools/cache/controller.go index fa78a4ca7b1..b4e8295ab1a 100644 --- a/staging/src/k8s.io/client-go/tools/cache/controller.go +++ b/staging/src/k8s.io/client-go/tools/cache/controller.go @@ -429,6 +429,14 @@ type InformerOptions struct { // for them. // Optional - if unset no additional transforming is happening. Transform TransformFunc + + // Identifier is used to identify the FIFO for metrics and logging purposes. + // If not set, metrics will not be published. + Identifier InformerNameAndResource + + // FIFOMetricsProvider is the metrics provider for the FIFO queue. + // If not set, metrics will be no-ops. + FIFOMetricsProvider FIFOMetricsProvider } // NewInformerWithOptions returns a Store and a controller for populating the store @@ -776,7 +784,7 @@ func newInformer(clientState Store, options InformerOptions, keyFunc KeyFunc) Co // KeyLister, that way resync operations will result in the correct set // of update/delete deltas. - fifo := newQueueFIFO(clientState, options.Transform) + fifo := newQueueFIFO(clientState, options.Transform, options.Identifier, options.FIFOMetricsProvider) cfg := &Config{ Queue: fifo, @@ -798,11 +806,13 @@ func newInformer(clientState Store, options InformerOptions, keyFunc KeyFunc) Co return New(cfg) } -func newQueueFIFO(clientState Store, transform TransformFunc) Queue { +func newQueueFIFO(clientState Store, transform TransformFunc, identifier InformerNameAndResource, metricsProvider FIFOMetricsProvider) Queue { if clientgofeaturegate.FeatureGates().Enabled(clientgofeaturegate.InOrderInformers) { options := RealFIFOOptions{ - KeyFunction: MetaNamespaceKeyFunc, - Transformer: transform, + KeyFunction: MetaNamespaceKeyFunc, + Transformer: transform, + Identifier: identifier, + MetricsProvider: metricsProvider, } // If atomic events are enabled, unset clientState in the case of atomic events as we cannot pass a // store to an atomic fifo. diff --git a/staging/src/k8s.io/client-go/tools/cache/reflector_data_consistency_detector_test.go b/staging/src/k8s.io/client-go/tools/cache/reflector_data_consistency_detector_test.go index 1d18d0be180..34abcb278a3 100644 --- a/staging/src/k8s.io/client-go/tools/cache/reflector_data_consistency_detector_test.go +++ b/staging/src/k8s.io/client-go/tools/cache/reflector_data_consistency_detector_test.go @@ -73,7 +73,7 @@ func runTestReflectorDataConsistencyDetector(t *testing.T, transformer Transform defer cancel() store := NewStore(MetaNamespaceKeyFunc) - fifo := newQueueFIFO(store, transformer) + fifo := newQueueFIFO(store, transformer, InformerNameAndResource{}, nil) lw := &ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { diff --git a/staging/src/k8s.io/client-go/tools/cache/shared_informer.go b/staging/src/k8s.io/client-go/tools/cache/shared_informer.go index bf58fe67829..fa1df736166 100644 --- a/staging/src/k8s.io/client-go/tools/cache/shared_informer.go +++ b/staging/src/k8s.io/client-go/tools/cache/shared_informer.go @@ -312,6 +312,8 @@ func NewSharedIndexInformerWithOptions(lw ListerWatcher, exampleObject runtime.O defaultEventHandlerResyncPeriod: options.ResyncPeriod, clock: realClock, cacheMutationDetector: NewCacheMutationDetector(fmt.Sprintf("%T", exampleObject)), + identifier: options.Identifier, + fifoMetricsProvider: options.FIFOMetricsProvider, keyFunc: DeletionHandlingMetaNamespaceKeyFunc, } } @@ -328,6 +330,14 @@ type SharedIndexInformerOptions struct { // ObjectDescription is the sharedIndexInformer's object description. This is passed through to the // underlying Reflector's type description. ObjectDescription string + + // Identifier is used to identify the FIFO for metrics and logging purposes. + // If not set, metrics will not be published. + Identifier InformerNameAndResource + + // FIFOMetricsProvider is the metrics provider for the FIFO queue. + // If not set, metrics will be no-ops. + FIFOMetricsProvider FIFOMetricsProvider } // InformerSynced is a function that can be used to determine if an informer has synced. This is useful for determining if caches have synced. @@ -451,6 +461,12 @@ type sharedIndexInformer struct { transform TransformFunc + // identifier is used to identify this informer for metrics and logging purposes. + identifier InformerNameAndResource + + // fifoMetricsProvider is the metrics provider for the FIFO queue. + fifoMetricsProvider FIFOMetricsProvider + // keyFunc is called when processing deltas by the underlying process function. keyFunc KeyFunc } @@ -543,7 +559,7 @@ func (s *sharedIndexInformer) RunWithContext(ctx context.Context) { s.startedLock.Lock() defer s.startedLock.Unlock() - fifo := newQueueFIFO(s.indexer, s.transform) + fifo := newQueueFIFO(s.indexer, s.transform, s.identifier, s.fifoMetricsProvider) cfg := &Config{ Queue: fifo,