mirror of
https://github.com/kubernetes/client-go.git
synced 2026-02-22 08:03:18 +00:00
Wire InformerName through SharedIndexInformer
Kubernetes-commit: 96386809339faee1169d163749cb4b7d354bec1e
This commit is contained in:
committed by
Kubernetes Publisher
parent
5fee0e4466
commit
12b64ed22e
18
tools/cache/controller.go
vendored
18
tools/cache/controller.go
vendored
@@ -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) {
|
||||
|
||||
18
tools/cache/shared_informer.go
vendored
18
tools/cache/shared_informer.go
vendored
@@ -316,6 +316,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,
|
||||
}
|
||||
}
|
||||
@@ -332,6 +334,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.
|
||||
@@ -455,6 +465,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
|
||||
}
|
||||
@@ -547,7 +563,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