kubernetes / kubernetes/kubernetes

Decoding should not clear apiVersion/kind

Open
#80,609 21 comments 55 reactions 0 assignees View on GitHub
help wanted kind/feature lifecycle/frozen sig/api-machinery triage/accepted
Dominant language
Go
Stars
128k
Forks
44.3k
Avg merge
5d 17h
Merged PRs (30d)
208

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

Open the contributing guide

Research direction

Start with staging/src/k8s.io/apimachinery/pkg/runtime/helper.go, especially the linked decoding logic, and the non-converting decoder in staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go. Trace typed-client decoding of versioned structs and determine how apiVersion/kind are cleared. Done means server-returned apiVersion/kind remain available on decoded versioned objects without changing internal-version conversion behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.