From c702a411d1828f50b6be17a5a40a952859371085 Mon Sep 17 00:00:00 2001 From: wojtekt Date: Thu, 23 Sep 2021 09:09:59 +0200 Subject: [PATCH] Create TransformingIndexerInformer Kubernetes-commit: 56ffb4e2b056622210bbf5ce845cf63ca18e85ce --- tools/cache/controller.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/cache/controller.go b/tools/cache/controller.go index 3f406490..c85c29db 100644 --- a/tools/cache/controller.go +++ b/tools/cache/controller.go @@ -385,6 +385,27 @@ func NewTransformingInformer( return clientState, newInformer(lw, objType, resyncPeriod, h, clientState, transformer) } +// NewTransformingIndexerInformer returns an Indexer and a controller for +// populating the index while also providing event notifications. You should +// only used the returned Index for Get/List operations; Add/Modify/Deletes +// will cause the event notifications to be faulty. +// The given transform function will be called on all objects before they will +// be put into the Index and corresponding Add/Modify/Delete handlers will +// be invoked for them. +func NewTransformingIndexerInformer( + lw ListerWatcher, + objType runtime.Object, + resyncPeriod time.Duration, + h ResourceEventHandler, + indexers Indexers, + transformer TransformFunc, +) (Indexer, Controller) { + // This will hold the client state, as we know it. + clientState := NewIndexer(DeletionHandlingMetaNamespaceKeyFunc, indexers) + + return clientState, newInformer(lw, objType, resyncPeriod, h, clientState, transformer) +} + // newInformer returns a controller for populating the store while also // providing event notifications. //