Skip to content

Commit 330c6e1

Browse files
committed
🐛 Cache bypass should take into account List types
Currently, when we create a new delegating client and we force some types to be uncached, we can only specify client.Object(s). When these objects are passed to the delegating client, and their GVK is matched against the internal map, the check doesn't take into account that the client might be issuing a List call with a ObjectList instead of a metav1.Object. The proposed solution is taken from the discovery rest mapper, which does the same ~hack. While it's not perfect, probably close to all generated objects are going to have a list that has the "List" suffix, that when removed gives back the original GVK. If there are other solutions, happy to change this hack. Signed-off-by: Vince Prignano <[email protected]>
1 parent 280bb8a commit 330c6e1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/client/split.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package client
1818

1919
import (
2020
"context"
21+
"strings"
2122

2223
"k8s.io/apimachinery/pkg/api/meta"
2324
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -99,6 +100,11 @@ func (d *delegatingReader) shouldBypassCache(obj runtime.Object) (bool, error) {
99100
if err != nil {
100101
return false, err
101102
}
103+
// TODO: this is producing unsafe guesses that don't actually work,
104+
// but it matches ~99% of the cases out there.
105+
if meta.IsListType(obj) {
106+
gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")
107+
}
102108
_, isUncached := d.uncachedGVKs[gvk]
103109
_, isUnstructured := obj.(*unstructured.Unstructured)
104110
_, isUnstructuredList := obj.(*unstructured.UnstructuredList)

0 commit comments

Comments
 (0)