Skip to content

Commit 46c061f

Browse files
committed
UPSTREAM: <carry>: only call cluster-aware keyFunc for cluster-aware cache
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
1 parent d9d2080 commit 46c061f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pkg/cache/cache.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"net/http"
23+
"strings"
2324
"time"
2425

2526
"github.com/kcp-dev/apimachinery/v2/third_party/informers"
@@ -391,6 +392,7 @@ func newCache(restConfig *rest.Config, opts Options) newCacheFunc {
391392
NewInformer: opts.NewInformerFunc,
392393
}),
393394
readerFailOnMissingInformer: opts.ReaderFailOnMissingInformer,
395+
clusterIndexes: strings.HasSuffix(restConfig.Host, "/clusters/*"),
394396
}
395397
}
396398
}

pkg/cache/informer_cache.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type informerCache struct {
7070
scheme *runtime.Scheme
7171
*internal.Informers
7272
readerFailOnMissingInformer bool
73+
clusterIndexes bool
7374
}
7475

7576
// Get implements Reader.
@@ -219,10 +220,10 @@ func (ic *informerCache) IndexField(ctx context.Context, obj client.Object, fiel
219220
if err != nil {
220221
return err
221222
}
222-
return indexByField(informer, field, extractValue)
223+
return indexByField(informer, field, extractValue, ic.clusterIndexes)
223224
}
224225

225-
func indexByField(informer Informer, field string, extractValue client.IndexerFunc) error {
226+
func indexByField(informer Informer, field string, extractValue client.IndexerFunc, clusterIndexes bool) error {
226227
indexFunc := func(objRaw interface{}) ([]string, error) {
227228
// TODO(directxman12): check if this is the correct type?
228229
obj, isObj := objRaw.(client.Object)
@@ -236,7 +237,7 @@ func indexByField(informer Informer, field string, extractValue client.IndexerFu
236237
ns := meta.GetNamespace()
237238

238239
keyFunc := internal.KeyToNamespacedKey
239-
if clusterName := logicalcluster.From(obj); !clusterName.Empty() {
240+
if clusterName := logicalcluster.From(obj); clusterIndexes && !clusterName.Empty() {
240241
keyFunc = func(ns, val string) string {
241242
return internal.KeyToClusteredKey(clusterName.String(), ns, val)
242243
}

0 commit comments

Comments
 (0)