mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Remove custom scheme stuff
As separate commit to make it easy to get back-- I'm not completely convince we won't want this in the future.
This commit is contained in:
parent
42dafb0e2e
commit
44f340f127
@ -34,36 +34,12 @@ type Scheme struct {
|
||||
raw *conversion.Scheme
|
||||
}
|
||||
|
||||
var namedSchemes map[string]*Scheme
|
||||
|
||||
// GetScheme returns the scheme with the given name, creating it if necessary.
|
||||
// Important: You may not modify the returned *Scheme except from init() functions.
|
||||
func GetScheme(schemeName string) *Scheme {
|
||||
if namedSchemes == nil {
|
||||
namedSchemes = map[string]*Scheme{}
|
||||
}
|
||||
if s, ok := namedSchemes[schemeName]; ok {
|
||||
return s
|
||||
}
|
||||
s := NewScheme("", "")
|
||||
namedSchemes[schemeName] = s
|
||||
return s
|
||||
}
|
||||
|
||||
// fromScope gets the input version, desired output version, and desired Scheme
|
||||
// from a conversion.Scope.
|
||||
func fromScope(s conversion.Scope) (inVersion, outVersion string, scheme *Scheme) {
|
||||
scheme = DefaultScheme
|
||||
inVersion = s.Meta().SrcVersion
|
||||
outVersion = s.Meta().DestVersion
|
||||
// If a scheme tag was provided, use it. Look at the struct tag corresponding
|
||||
// to version "".
|
||||
if name := s.SrcTag().Get("scheme"); inVersion == "" && name != "" {
|
||||
scheme = GetScheme(name)
|
||||
}
|
||||
if name := s.DestTag().Get("scheme"); outVersion == "" && name != "" {
|
||||
scheme = GetScheme(name)
|
||||
}
|
||||
return inVersion, outVersion, scheme
|
||||
}
|
||||
|
||||
|
@ -153,28 +153,22 @@ type ExternalExtensionType struct {
|
||||
}
|
||||
|
||||
type InternalExtensionType struct {
|
||||
JSONBase `json:",inline" yaml:",inline"`
|
||||
Extension runtime.EmbeddedObject `json:"extension" yaml:"extension" scheme:"testExtension"`
|
||||
}
|
||||
|
||||
type InternalExtensionTypeNoScheme struct {
|
||||
JSONBase `json:",inline" yaml:",inline"`
|
||||
Extension runtime.EmbeddedObject `json:"extension" yaml:"extension"`
|
||||
}
|
||||
|
||||
func (*ExtensionA) IsAnAPIObject() {}
|
||||
func (*ExtensionB) IsAnAPIObject() {}
|
||||
func (*ExternalExtensionType) IsAnAPIObject() {}
|
||||
func (*InternalExtensionType) IsAnAPIObject() {}
|
||||
func (*InternalExtensionTypeNoScheme) IsAnAPIObject() {}
|
||||
func (*ExtensionA) IsAnAPIObject() {}
|
||||
func (*ExtensionB) IsAnAPIObject() {}
|
||||
func (*ExternalExtensionType) IsAnAPIObject() {}
|
||||
func (*InternalExtensionType) IsAnAPIObject() {}
|
||||
|
||||
func TestExtensionMappingWithScheme(t *testing.T) {
|
||||
func TestExtensionMapping(t *testing.T) {
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("", "ExtensionType", &InternalExtensionType{})
|
||||
runtime.GetScheme("testExtension").AddKnownTypeWithName("", "A", &ExtensionA{})
|
||||
runtime.GetScheme("testExtension").AddKnownTypeWithName("", "B", &ExtensionB{})
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("", "A", &ExtensionA{})
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("", "B", &ExtensionB{})
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("testExternal", "ExtensionType", &ExternalExtensionType{})
|
||||
runtime.GetScheme("testExtension").AddKnownTypeWithName("testExternal", "A", &ExtensionA{})
|
||||
runtime.GetScheme("testExtension").AddKnownTypeWithName("testExternal", "B", &ExtensionB{})
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("testExternal", "A", &ExtensionA{})
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("testExternal", "B", &ExtensionB{})
|
||||
|
||||
table := []struct {
|
||||
obj runtime.Object
|
||||
@ -215,43 +209,3 @@ func TestExtensionMappingWithScheme(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtensionMappingWithoutScheme(t *testing.T) {
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("", "ExtensionType", &InternalExtensionTypeNoScheme{})
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("", "ExA", &ExtensionA{})
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("testExternal", "ExtensionType", &ExternalExtensionType{})
|
||||
runtime.DefaultScheme.AddKnownTypeWithName("testExternal", "ExA", &ExtensionA{})
|
||||
|
||||
table := []struct {
|
||||
obj runtime.Object
|
||||
encoded string
|
||||
}{
|
||||
{
|
||||
&InternalExtensionTypeNoScheme{Extension: runtime.EmbeddedObject{&ExtensionA{TestString: "foo"}}},
|
||||
`{"kind":"ExtensionType","apiVersion":"testExternal","extension":{"kind":"ExA","testString":"foo"}}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, item := range table {
|
||||
gotEncoded, err := runtime.DefaultScheme.EncodeToVersion(item.obj, "testExternal")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error '%v' (%#v)", err, item.obj)
|
||||
} else if e, a := item.encoded, string(gotEncoded); e != a {
|
||||
t.Errorf("expected %v, got %v", e, a)
|
||||
}
|
||||
|
||||
gotDecoded, err := runtime.DefaultScheme.Decode([]byte(item.encoded))
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error '%v' (%v)", err, item.encoded)
|
||||
} else if e, a := item.obj, gotDecoded; !reflect.DeepEqual(e, a) {
|
||||
var eEx, aEx runtime.Object
|
||||
if obj, ok := e.(*InternalExtensionTypeNoScheme); ok {
|
||||
eEx = obj.Extension.Object
|
||||
}
|
||||
if obj, ok := a.(*InternalExtensionTypeNoScheme); ok {
|
||||
aEx = obj.Extension.Object
|
||||
}
|
||||
t.Errorf("expected %#v, got %#v (%#v, %#v)", e, a, eEx, aEx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,8 +72,7 @@ type EmbeddedObject struct {
|
||||
// // Internal package:
|
||||
// type MyAPIObject struct {
|
||||
// runtime.JSONBase `yaml:",inline" json:",inline"`
|
||||
// // The "scheme" tag is optional; if absent, runtime.DefaultScheme will be used.
|
||||
// MyPlugin runtime.EmbeddedObject `scheme:"pluginScheme"`
|
||||
// MyPlugin runtime.EmbeddedObject `json:"myPlugin" yaml:"myPlugin"`
|
||||
// }
|
||||
// type PluginA struct {
|
||||
// runtime.PluginBase `yaml:",inline" json:",inline"`
|
||||
|
Loading…
Reference in New Issue
Block a user