From ca9d1f728b2bc08b3f8cb35f3b32ffdf4c12d765 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Thu, 5 Apr 2018 13:47:44 +0200 Subject: [PATCH] apimachinery duct tape: handle empty unstructured GV in versioning codec gracefully --- .../pkg/runtime/serializer/versioning/versioning.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go b/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go index aedec75ee0e..004e5c33718 100644 --- a/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go +++ b/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go @@ -171,8 +171,11 @@ func (c *codec) Encode(obj runtime.Object, w io.Writer) error { case *runtime.Unknown: return c.encoder.Encode(obj, w) case runtime.Unstructured: - // avoid conversion roundtrip if GVK is the right one already + // avoid conversion roundtrip if GVK is the right one already or is empty (yes, this is a hack, but the old behaviour we rely on in kubectl) objGVK := obj.GetObjectKind().GroupVersionKind() + if len(objGVK.Version) == 0 { + return c.encoder.Encode(obj, w) + } targetGVK, ok := c.encodeVersion.KindForGroupVersionKinds([]schema.GroupVersionKind{objGVK}) if !ok { return runtime.NewNotRegisteredErrForTarget(reflect.TypeOf(obj).Elem(), c.encodeVersion)