mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Wire InformerName through SharedIndexInformer
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user