From 051382687d4ddcb85ffea9c0f95d1671e6dd18c2 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Tue, 1 Nov 2016 21:37:13 -0400 Subject: [PATCH] Unversioned types should decode no matter what the requested version is Status is exposed as v1 in the current schema (so all groups are returning v1.Status). However, if you give a codec only "mygroup" "myversion", it will fail to convert Status to v1. For now, unversioned types should be allowed to be projected into all group versions, and when we add the server group we'll rip out the unversioned concept entirely. --- pkg/runtime/scheme.go | 9 +++++++++ pkg/runtime/scheme_test.go | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/runtime/scheme.go b/pkg/runtime/scheme.go index fdd4d1f44fa..0b42feae420 100644 --- a/pkg/runtime/scheme.go +++ b/pkg/runtime/scheme.go @@ -519,6 +519,15 @@ func (s *Scheme) convertToVersion(copy bool, in Object, target GroupVersioner) ( gvk, ok := target.KindForGroupVersionKinds(kinds) if !ok { + // try to see if this type is listed as unversioned (for legacy support) + // TODO: when we move to server API versions, we should completely remove the unversioned concept + if unversionedKind, ok := s.unversionedTypes[t]; ok { + if gvk, ok := target.KindForGroupVersionKinds([]unversioned.GroupVersionKind{unversionedKind}); ok { + return copyAndSetTargetKind(copy, s, in, gvk) + } + return copyAndSetTargetKind(copy, s, in, unversionedKind) + } + // TODO: should this be a typed error? return nil, fmt.Errorf("%v is not suitable for converting to %q", t, target) } diff --git a/pkg/runtime/scheme_test.go b/pkg/runtime/scheme_test.go index 2d71d412714..b51a8aff287 100644 --- a/pkg/runtime/scheme_test.go +++ b/pkg/runtime/scheme_test.go @@ -625,6 +625,17 @@ func TestConvertToVersion(t *testing.T) { A: "test", }, }, + // unversioned type returned when not included in the target types + { + scheme: GetTestScheme(), + in: &UnversionedType{A: "test"}, + gv: unversioned.GroupVersions{{Group: "other", Version: "v2"}}, + same: true, + out: &UnversionedType{ + MyWeirdCustomEmbeddedVersionKindField: MyWeirdCustomEmbeddedVersionKindField{APIVersion: "v1", ObjectKind: "UnversionedType"}, + A: "test", + }, + }, // detected as already being in the target version { scheme: GetTestScheme(),