Skip to content

🐛 Re-wire additional indexers into informers creation #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ func newCache(restConfig *rest.Config, opts Options) newCacheFunc {
Transform: config.Transform,
UnsafeDisableDeepCopy: pointer.BoolDeref(config.UnsafeDisableDeepCopy, false),
NewInformer: opts.NewInformerFunc,
Indexers: opts.Indexers,
}),
readerFailOnMissingInformer: opts.ReaderFailOnMissingInformer,
}
Expand Down
19 changes: 16 additions & 3 deletions pkg/cache/internal/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type InformersOpts struct {
Selector Selector
Transform cache.TransformFunc
UnsafeDisableDeepCopy bool
Indexers cache.Indexers
}

// NewInformers creates a new InformersMap that can create informers under the hood.
Expand Down Expand Up @@ -78,6 +79,7 @@ func NewInformers(config *rest.Config, options *InformersOpts) *Informers {
transform: options.Transform,
unsafeDisableDeepCopy: options.UnsafeDisableDeepCopy,
newInformer: newInformer,
indexers: options.Indexers,
}
}

Expand Down Expand Up @@ -155,6 +157,9 @@ type Informers struct {
// default or empty string means all namespaces
namespace string

// indexers is a list of additional indexers to use when creating a new informer
indexers cache.Indexers

selector Selector
transform cache.TransformFunc
unsafeDisableDeepCopy bool
Expand Down Expand Up @@ -311,6 +316,16 @@ func (ip *Informers) addInformerToMap(gvk schema.GroupVersionKind, obj runtime.O
if err != nil {
return nil, false, err
}

indexers := cache.Indexers{
cache.NamespaceIndex: cache.MetaNamespaceIndexFunc,
}

// Append additional indexers that might be passed.
for key := range ip.indexers {
indexers[key] = ip.indexers[key]
}

sharedIndexInformer := ip.newInformer(&cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ip.selector.ApplyToList(&opts)
Expand All @@ -321,9 +336,7 @@ func (ip *Informers) addInformerToMap(gvk schema.GroupVersionKind, obj runtime.O
opts.Watch = true // Watch needs to be set to true separately
return listWatcher.WatchFunc(opts)
},
}, obj, calculateResyncPeriod(ip.resync), cache.Indexers{
cache.NamespaceIndex: cache.MetaNamespaceIndexFunc,
})
}, obj, calculateResyncPeriod(ip.resync), indexers)

// Check to see if there is a transformer for this gvk
if err := sharedIndexInformer.SetTransform(ip.transform); err != nil {
Expand Down