Skip to content

Commit

Permalink
Add support for CATTLE_GLOBAL_LABEL_SELECTOR env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar authored and hifi committed Jan 16, 2025
1 parent a80bf83 commit 239b8be
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/clustercache/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clustercache

import (
"context"
"os"
"sync"
"time"

Expand Down Expand Up @@ -124,6 +125,17 @@ func (h *clusterCache) addResourceEventHandler(gvk schema2.GroupVersionKind, inf
})
}

func getTweakListOptions() informer.TweakListOptionsFunc {
globalLabelSelector := os.Getenv("CATTLE_GLOBAL_LABEL_SELECTOR")
if globalLabelSelector == "" {
return func(*metav1.ListOptions) {}
}
return func(opts *metav1.ListOptions) {
logrus.Infof("Applying global label selector: %s", globalLabelSelector)
opts.LabelSelector = globalLabelSelector
}
}

func (h *clusterCache) OnSchemas(schemas *schema.Collection) error {
h.Lock()
defer h.Unlock()
Expand All @@ -148,7 +160,7 @@ func (h *clusterCache) OnSchemas(schemas *schema.Collection) error {
}

summaryInformer := informer.NewFilteredSummaryInformer(h.summaryClient, gvr, metav1.NamespaceAll, 2*time.Hour,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, nil)
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, getTweakListOptions())
ctx, cancel := context.WithCancel(h.ctx)
w := &watcher{
ctx: ctx,
Expand Down

0 comments on commit 239b8be

Please sign in to comment.