kubernetes/kubernetes

Decoding should not clear apiVersion/kind

Open

#80,609 opened on Jul 25, 2019

View on GitHub
 (21 comments) (55 reactions) (0 assignees)Go (43,066 forks)batch import
help wantedkind/featurelifecycle/frozensig/api-machinerytriage/accepted

Repository metrics

Stars
 (122,268 stars)
PR merge metrics
 (Avg merge 28d 17h) (343 merged PRs in 30d)

Description

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)

Contributor guide