You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
client: CacheReader returns typed objects with empty GVK when UnsafeDisableDeepCopy is enabled #3606
CacheReader restores an object's GroupVersionKind only on deep-copy. With UnsafeDisableDeepCopy enabled option, typed objects come back from Get and List with an empty TypeMeta.
Code that switches on the GVK (webhooks, generic reconcilers, kind-keyed event handlers) then
misbehaves silently, and only for users who turned the option on for performance(that's my case in EG).
How to reproduce
c, _:=cache.New(cfg, cache.Options{DefaultUnsafeDisableDeepCopy: ptr.To(true)})
out:=&corev1.Pod{}
_=c.Get(ctx, key, out)
fmt.Println(out.GetObjectKind().GroupVersionKind()) // it's empatylist:=&corev1.PodList{}
_=c.List(ctx, list)
fmt.Println(list.Items[0].GroupVersionKind()) // empty as well
Why it happens
Two independent things have to line up:
The GVK is stripped at decode. runtime.WithoutVersionDecoder clears the GVK after deserialization apimachinery/pkg/runtime/helper.go:255-262, "clearing the gvk is just a convention of a codec"). I could guess it's because TypeMeta creates a second representation of the object's identity that could conflict with the instantiated object.
Disable deep copy and nothing gonna restore it(but It affects only structured informers)
Suggested fix
Set GVK in Get and List whenever it is absent, rather than only on the deep-copy branch.
The skip was never needed for safety: Get shallow-copies into the caller's out before the guarded set, and for a typed object TypeMeta is a value field of that copy; after apimeta.SetList the items of a concretely typed Items slice are likewise copies.
But there's a couple of corner-cases.
Unstructured must not be written to.SetGroupVersionKind on it is unconditional map write, so an unguarded set would mutate live cache state. Also like i said only structured informers affected because unstructured always arrives with apiVersion/kind populated.
Some list shapes hold the cache's own objects. So we gonna skip them
Activity
stillya commentedon Sep 28, 2026
ready to contribute if you consider it relevant.
alvaroaleman commentedon Sep 30, 2026
If anything, the bug here is that its ever set on a typed object. Use
apiutil.GVKForObjectif you want to get the GVK for an object.