-
Notifications
You must be signed in to change notification settings - Fork 41.1k
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:
kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/helper.go
Lines 245 to 259 in 69a34f6
// WithoutVersionDecoder clears the group version kind of a deserialized object. | |
type WithoutVersionDecoder struct { | |
Decoder | |
} | |
// Decode does not do conversion. It removes the gvk during deserialization. | |
func (d WithoutVersionDecoder) Decode(data []byte, defaults *schema.GroupVersionKind, into Object) (Object, *schema.GroupVersionKind, error) { | |
obj, gvk, err := d.Decoder.Decode(data, defaults, into) | |
if obj != nil { | |
kind := obj.GetObjectKind() | |
// clearing the gvk is just a convention of a codec | |
kind.SetGroupVersionKind(schema.GroupVersionKind{}) | |
} | |
return obj, gvk, err | |
} |
This is the decoder used when a client requests a decoder that does not do conversion:
kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go
Lines 175 to 179 in 69a34f6
// WithoutConversion returns a NegotiatedSerializer that performs no conversion, even if the | |
// caller requests it. | |
func (f CodecFactory) WithoutConversion() runtime.NegotiatedSerializer { | |
return WithoutConversionCodecFactory{f} | |
} |
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 #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 kubernetes-sigs/controller-runtime#526)