mirror of https://github.com/k3s-io/k3s
Add runtime.ObjectConvertor to RESTMapper
parent
dc862ae463
commit
f0c23d68f7
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue