kubernetes: Decoding should not clear apiVersion/kind

What would you like to be added: When using a typed client, decoding to a versioned struct (not an internal API type), the apiVersion/kind information returned from the server should not be dropped.

Why is this needed: The GroupVersionKind() method included in the ObjectKind interface is largely useless when dealing with arbitrary runtime.Object instances, since typed instances drop this information here:

https://github.com/kubernetes/kubernetes/blob/69a34f6a6f67de47cb9b72b6ac98e089d301beb3/staging/src/k8s.io/apimachinery/pkg/runtime/helper.go#L245-L259

This is the decoder used when a client requests a decoder that does not do conversion:

https://github.com/kubernetes/kubernetes/blob/69a34f6a6f67de47cb9b72b6ac98e089d301beb3/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go#L175-L179

I could see clearing group/version/kind information when converting to an internal version, but I don’t see the benefit of stripping it on decode if we’re only dealing with a versioned struct.

/sig api-machinery /cc @smarterclayton

Note that https://github.com/kubernetes/kubernetes/issues/3030 still needs to be resolved before apiVersion/kind could be depended on for individual objects for all API responses, but this would at least solve the issue with an update of an object clearing the apiVersion/kind in an update response (xref https://github.com/kubernetes-sigs/controller-runtime/issues/526)

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 41
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted comments

it is still an issue on the latest version 😃

/reopen

I doubt a PR to cluster-api fixed this

Is there a real million stone for this issue? I see you moved this from v1.19 to v1.20

Although typed resource is already known to user, it’s a bit weird to explicitly remove the GVK from de-serialized struct. The explicit behavior sometimes makes things harder, eg: Printing struct Kind and version, without filled TypeMeta, I need reflect package to do so. Any comments or suggestion?