diff --git a/pkg/api/latest/latest.go b/pkg/api/latest/latest.go index 64303b1b29b..69c0108796d 100644 --- a/pkg/api/latest/latest.go +++ b/pkg/api/latest/latest.go @@ -71,11 +71,13 @@ func InterfacesFor(version string) (*meta.VersionInterfaces, error) { case "v1beta1": return &meta.VersionInterfaces{ Codec: v1beta1.Codec, + ObjectConvertor: api.Scheme, MetadataAccessor: accessor, }, nil case "v1beta2": return &meta.VersionInterfaces{ Codec: v1beta2.Codec, + ObjectConvertor: api.Scheme, MetadataAccessor: accessor, }, nil default: diff --git a/pkg/api/meta/interfaces.go b/pkg/api/meta/interfaces.go index f3494abfecd..9674a015365 100644 --- a/pkg/api/meta/interfaces.go +++ b/pkg/api/meta/interfaces.go @@ -23,6 +23,7 @@ import ( // VersionInterfaces contains the interfaces one should use for dealing with types of a particular version. type VersionInterfaces struct { runtime.Codec + runtime.ObjectConvertor MetadataAccessor } @@ -86,6 +87,7 @@ type RESTMapping struct { Kind string runtime.Codec + runtime.ObjectConvertor MetadataAccessor } diff --git a/pkg/api/meta/restmapper.go b/pkg/api/meta/restmapper.go index 92d1278555a..5a041452138 100644 --- a/pkg/api/meta/restmapper.go +++ b/pkg/api/meta/restmapper.go @@ -49,7 +49,7 @@ type DefaultRESTMapper struct { interfacesFunc VersionInterfacesFunc } -// VersionInterfacesFunc returns the appropriate codec and metadata accessor for a +// VersionInterfacesFunc returns the appropriate codec, typer, and metadata accessor for a // given api version, or false if no such api version exists. type VersionInterfacesFunc func(apiVersion string) (*VersionInterfaces, bool) @@ -162,6 +162,7 @@ func (m *DefaultRESTMapper) RESTMapping(version, kind string) (*RESTMapping, err Kind: kind, Codec: interfaces.Codec, + ObjectConvertor: interfaces.ObjectConvertor, MetadataAccessor: interfaces.MetadataAccessor, }, nil } diff --git a/pkg/api/meta/restmapper_test.go b/pkg/api/meta/restmapper_test.go index 3935101face..09db97332e4 100644 --- a/pkg/api/meta/restmapper_test.go +++ b/pkg/api/meta/restmapper_test.go @@ -36,11 +36,18 @@ func (fakeCodec) DecodeInto([]byte, runtime.Object) error { return nil } +type fakeConvertor struct{} + +func (fakeConvertor) ConvertToVersion(in runtime.Object, _ string) (runtime.Object, error) { + return in, nil +} + var validCodec = fakeCodec{} var validAccessor = resourceAccessor{} +var validConvertor = fakeConvertor{} func fakeInterfaces(version string) (*VersionInterfaces, bool) { - return &VersionInterfaces{Codec: validCodec, MetadataAccessor: validAccessor}, true + return &VersionInterfaces{Codec: validCodec, ObjectConvertor: validConvertor, MetadataAccessor: validAccessor}, true } func unmatchedVersionInterfaces(version string) (*VersionInterfaces, bool) { @@ -155,7 +162,7 @@ func TestRESTMapperRESTMapping(t *testing.T) { if mapping.APIVersion != version { t.Errorf("%d: unexpected version: %#v", i, mapping) } - if mapping.Codec == nil || mapping.MetadataAccessor == nil { + if mapping.Codec == nil || mapping.MetadataAccessor == nil || mapping.ObjectConvertor == nil { t.Errorf("%d: missing codec and accessor: %#v", i, mapping) } }