mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Merge pull request #89821 from wojtek-t/cleanup_apimachinery_tests
Cleanup apimachinery tests and stop relying on default conversions
This commit is contained in:
commit
9c3b5887d2
@ -289,7 +289,6 @@ staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json
|
|||||||
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/protobuf
|
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/protobuf
|
||||||
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/recognizer
|
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/recognizer
|
||||||
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/streaming
|
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/streaming
|
||||||
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/testing
|
|
||||||
staging/src/k8s.io/apimachinery/pkg/runtime/testing
|
staging/src/k8s.io/apimachinery/pkg/runtime/testing
|
||||||
staging/src/k8s.io/apimachinery/pkg/selection
|
staging/src/k8s.io/apimachinery/pkg/selection
|
||||||
staging/src/k8s.io/apimachinery/pkg/test
|
staging/src/k8s.io/apimachinery/pkg/test
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
runtimetesting "k8s.io/apimachinery/pkg/runtime/testing"
|
runtimetesting "k8s.io/apimachinery/pkg/runtime/testing"
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
|
func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
|
||||||
@ -37,6 +38,7 @@ func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
|
|||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
s.AddKnownTypes(internalGV, &runtimetesting.ObjectTest{})
|
s.AddKnownTypes(internalGV, &runtimetesting.ObjectTest{})
|
||||||
s.AddKnownTypeWithName(externalGVK, &runtimetesting.ObjectTestExternal{})
|
s.AddKnownTypeWithName(externalGVK, &runtimetesting.ObjectTestExternal{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(s))
|
||||||
|
|
||||||
codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV)
|
codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV)
|
||||||
|
|
||||||
@ -74,6 +76,7 @@ func TestArrayOfRuntimeObject(t *testing.T) {
|
|||||||
s.AddKnownTypeWithName(externalGV.WithKind("EmbeddedTest"), &runtimetesting.EmbeddedTestExternal{})
|
s.AddKnownTypeWithName(externalGV.WithKind("EmbeddedTest"), &runtimetesting.EmbeddedTestExternal{})
|
||||||
s.AddKnownTypes(internalGV, &runtimetesting.ObjectTest{})
|
s.AddKnownTypes(internalGV, &runtimetesting.ObjectTest{})
|
||||||
s.AddKnownTypeWithName(externalGV.WithKind("ObjectTest"), &runtimetesting.ObjectTestExternal{})
|
s.AddKnownTypeWithName(externalGV.WithKind("ObjectTest"), &runtimetesting.ObjectTestExternal{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(s))
|
||||||
|
|
||||||
codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV)
|
codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV)
|
||||||
|
|
||||||
@ -148,6 +151,7 @@ func TestNestedObject(t *testing.T) {
|
|||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
s.AddKnownTypes(internalGV, &runtimetesting.EmbeddedTest{})
|
s.AddKnownTypes(internalGV, &runtimetesting.EmbeddedTest{})
|
||||||
s.AddKnownTypeWithName(embeddedTestExternalGVK, &runtimetesting.EmbeddedTestExternal{})
|
s.AddKnownTypeWithName(embeddedTestExternalGVK, &runtimetesting.EmbeddedTestExternal{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(s))
|
||||||
|
|
||||||
codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV)
|
codec := serializer.NewCodecFactory(s).LegacyCodec(externalGV)
|
||||||
|
|
||||||
@ -227,6 +231,7 @@ func TestDeepCopyOfRuntimeObject(t *testing.T) {
|
|||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
s.AddKnownTypes(internalGV, &runtimetesting.EmbeddedTest{})
|
s.AddKnownTypes(internalGV, &runtimetesting.EmbeddedTest{})
|
||||||
s.AddKnownTypeWithName(embeddedTestExternalGVK, &runtimetesting.EmbeddedTestExternal{})
|
s.AddKnownTypeWithName(embeddedTestExternalGVK, &runtimetesting.EmbeddedTestExternal{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(s))
|
||||||
|
|
||||||
original := &runtimetesting.EmbeddedTest{
|
original := &runtimetesting.EmbeddedTest{
|
||||||
ID: "outer",
|
ID: "outer",
|
||||||
|
@ -37,23 +37,15 @@ type testConversions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *testConversions) internalToExternalSimple(in *runtimetesting.InternalSimple, out *runtimetesting.ExternalSimple, scope conversion.Scope) error {
|
func (c *testConversions) internalToExternalSimple(in *runtimetesting.InternalSimple, out *runtimetesting.ExternalSimple, scope conversion.Scope) error {
|
||||||
if err := scope.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
out.TypeMeta = in.TypeMeta
|
||||||
return err
|
out.TestString = in.TestString
|
||||||
}
|
|
||||||
if err := scope.Convert(&in.TestString, &out.TestString, 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.internalToExternalCalls++
|
c.internalToExternalCalls++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testConversions) externalToInternalSimple(in *runtimetesting.ExternalSimple, out *runtimetesting.InternalSimple, scope conversion.Scope) error {
|
func (c *testConversions) externalToInternalSimple(in *runtimetesting.ExternalSimple, out *runtimetesting.InternalSimple, scope conversion.Scope) error {
|
||||||
if err := scope.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
out.TypeMeta = in.TypeMeta
|
||||||
return err
|
out.TestString = in.TestString
|
||||||
}
|
|
||||||
if err := scope.Convert(&in.TestString, &out.TestString, 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.externalToInternalCalls++
|
c.externalToInternalCalls++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -81,6 +73,7 @@ func TestScheme(t *testing.T) {
|
|||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
scheme.AddKnownTypeWithName(internalGVK, &runtimetesting.InternalSimple{})
|
scheme.AddKnownTypeWithName(internalGVK, &runtimetesting.InternalSimple{})
|
||||||
scheme.AddKnownTypeWithName(externalGVK, &runtimetesting.ExternalSimple{})
|
scheme.AddKnownTypeWithName(externalGVK, &runtimetesting.ExternalSimple{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(scheme))
|
||||||
|
|
||||||
// If set, would clear TypeMeta during conversion.
|
// If set, would clear TypeMeta during conversion.
|
||||||
//scheme.AddIgnoredConversionType(&TypeMeta{}, &TypeMeta{})
|
//scheme.AddIgnoredConversionType(&TypeMeta{}, &TypeMeta{})
|
||||||
@ -94,9 +87,7 @@ func TestScheme(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Register functions to verify that scope.Meta() gets set correctly.
|
// Register functions to verify that scope.Meta() gets set correctly.
|
||||||
if err := conversions.registerConversions(scheme); err != nil {
|
utilruntime.Must(conversions.registerConversions(scheme))
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("Encode, Decode, DecodeInto, and DecodeToVersion", func(t *testing.T) {
|
t.Run("Encode, Decode, DecodeInto, and DecodeToVersion", func(t *testing.T) {
|
||||||
simple := &runtimetesting.InternalSimple{
|
simple := &runtimetesting.InternalSimple{
|
||||||
@ -272,6 +263,7 @@ func TestExternalToInternalMapping(t *testing.T) {
|
|||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
scheme.AddKnownTypeWithName(internalGV.WithKind("OptionalExtensionType"), &runtimetesting.InternalOptionalExtensionType{})
|
scheme.AddKnownTypeWithName(internalGV.WithKind("OptionalExtensionType"), &runtimetesting.InternalOptionalExtensionType{})
|
||||||
scheme.AddKnownTypeWithName(externalGV.WithKind("OptionalExtensionType"), &runtimetesting.ExternalOptionalExtensionType{})
|
scheme.AddKnownTypeWithName(externalGV.WithKind("OptionalExtensionType"), &runtimetesting.ExternalOptionalExtensionType{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(scheme))
|
||||||
|
|
||||||
codec := serializer.NewCodecFactory(scheme).LegacyCodec(externalGV)
|
codec := serializer.NewCodecFactory(scheme).LegacyCodec(externalGV)
|
||||||
|
|
||||||
@ -311,6 +303,7 @@ func TestExtensionMapping(t *testing.T) {
|
|||||||
scheme.AddKnownTypeWithName(externalGV.WithKind("B"), &runtimetesting.ExtensionB{})
|
scheme.AddKnownTypeWithName(externalGV.WithKind("B"), &runtimetesting.ExtensionB{})
|
||||||
scheme.AddKnownTypeWithName(internalGV.WithKind("A"), &runtimetesting.ExtensionA{})
|
scheme.AddKnownTypeWithName(internalGV.WithKind("A"), &runtimetesting.ExtensionA{})
|
||||||
scheme.AddKnownTypeWithName(internalGV.WithKind("B"), &runtimetesting.ExtensionB{})
|
scheme.AddKnownTypeWithName(internalGV.WithKind("B"), &runtimetesting.ExtensionB{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(scheme))
|
||||||
|
|
||||||
codec := serializer.NewCodecFactory(scheme).LegacyCodec(externalGV)
|
codec := serializer.NewCodecFactory(scheme).LegacyCodec(externalGV)
|
||||||
|
|
||||||
@ -379,6 +372,7 @@ func TestEncode(t *testing.T) {
|
|||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
scheme.AddKnownTypeWithName(internalGVK, &runtimetesting.InternalSimple{})
|
scheme.AddKnownTypeWithName(internalGVK, &runtimetesting.InternalSimple{})
|
||||||
scheme.AddKnownTypeWithName(externalGVK, &runtimetesting.ExternalSimple{})
|
scheme.AddKnownTypeWithName(externalGVK, &runtimetesting.ExternalSimple{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(scheme))
|
||||||
|
|
||||||
codec := serializer.NewCodecFactory(scheme).LegacyCodec(externalGV)
|
codec := serializer.NewCodecFactory(scheme).LegacyCodec(externalGV)
|
||||||
|
|
||||||
@ -414,6 +408,7 @@ func TestUnversionedTypes(t *testing.T) {
|
|||||||
scheme.AddKnownTypeWithName(internalGVK, &runtimetesting.InternalSimple{})
|
scheme.AddKnownTypeWithName(internalGVK, &runtimetesting.InternalSimple{})
|
||||||
scheme.AddKnownTypeWithName(externalGVK, &runtimetesting.ExternalSimple{})
|
scheme.AddKnownTypeWithName(externalGVK, &runtimetesting.ExternalSimple{})
|
||||||
scheme.AddKnownTypeWithName(otherGV.WithKind("Simple"), &runtimetesting.ExternalSimple{})
|
scheme.AddKnownTypeWithName(otherGV.WithKind("Simple"), &runtimetesting.ExternalSimple{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(scheme))
|
||||||
|
|
||||||
codec := serializer.NewCodecFactory(scheme).LegacyCodec(externalGV)
|
codec := serializer.NewCodecFactory(scheme).LegacyCodec(externalGV)
|
||||||
|
|
||||||
@ -488,14 +483,8 @@ func GetTestScheme() *runtime.Scheme {
|
|||||||
s.AddKnownTypeWithName(alternateExternalGV.WithKind("TestType5"), &runtimetesting.ExternalTestType1{})
|
s.AddKnownTypeWithName(alternateExternalGV.WithKind("TestType5"), &runtimetesting.ExternalTestType1{})
|
||||||
s.AddKnownTypeWithName(differentExternalGV.WithKind("TestType1"), &runtimetesting.ExternalTestType1{})
|
s.AddKnownTypeWithName(differentExternalGV.WithKind("TestType1"), &runtimetesting.ExternalTestType1{})
|
||||||
s.AddUnversionedTypes(externalGV, &runtimetesting.UnversionedType{})
|
s.AddUnversionedTypes(externalGV, &runtimetesting.UnversionedType{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(s))
|
||||||
|
|
||||||
convertTestType := func(in *runtimetesting.TestType1, out *runtimetesting.ExternalTestType1, s conversion.Scope) error {
|
|
||||||
out.A = in.A
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
utilruntime.Must(s.AddConversionFunc((*runtimetesting.TestType1)(nil), (*runtimetesting.ExternalTestType1)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
|
||||||
return convertTestType(a.(*runtimetesting.TestType1), b.(*runtimetesting.ExternalTestType1), scope)
|
|
||||||
}))
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -941,6 +930,7 @@ func TestMetaValues(t *testing.T) {
|
|||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
s.AddKnownTypeWithName(internalGV.WithKind("Simple"), &runtimetesting.InternalSimple{})
|
s.AddKnownTypeWithName(internalGV.WithKind("Simple"), &runtimetesting.InternalSimple{})
|
||||||
s.AddKnownTypeWithName(externalGV.WithKind("Simple"), &runtimetesting.ExternalSimple{})
|
s.AddKnownTypeWithName(externalGV.WithKind("Simple"), &runtimetesting.ExternalSimple{})
|
||||||
|
utilruntime.Must(runtimetesting.RegisterConversions(s))
|
||||||
|
|
||||||
conversions := &testConversions{
|
conversions := &testConversions{
|
||||||
internalToExternalCalls: 0,
|
internalToExternalCalls: 0,
|
||||||
@ -948,9 +938,8 @@ func TestMetaValues(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Register functions to verify that scope.Meta() gets set correctly.
|
// Register functions to verify that scope.Meta() gets set correctly.
|
||||||
if err := conversions.registerConversions(s); err != nil {
|
utilruntime.Must(conversions.registerConversions(s))
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
simple := &runtimetesting.InternalSimple{
|
simple := &runtimetesting.InternalSimple{
|
||||||
TestString: "foo",
|
TestString: "foo",
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ go_test(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/testing:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/testing:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||||
"//vendor/github.com/google/gofuzz:go_default_library",
|
"//vendor/github.com/google/gofuzz:go_default_library",
|
||||||
@ -61,7 +61,6 @@ filegroup(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/protobuf:all-srcs",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/protobuf:all-srcs",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/recognizer:all-srcs",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/recognizer:all-srcs",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/streaming:all-srcs",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/streaming:all-srcs",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/testing:all-srcs",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning:all-srcs",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning:all-srcs",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/yaml:all-srcs",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/yaml:all-srcs",
|
||||||
],
|
],
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/conversion"
|
"k8s.io/apimachinery/pkg/conversion"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
serializertesting "k8s.io/apimachinery/pkg/runtime/serializer/testing"
|
runtimetesting "k8s.io/apimachinery/pkg/runtime/testing"
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ func (testMetaFactory) Interpret(data []byte) (*schema.GroupVersionKind, error)
|
|||||||
|
|
||||||
// TestObjectFuzzer can randomly populate all the above objects.
|
// TestObjectFuzzer can randomly populate all the above objects.
|
||||||
var TestObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 100).Funcs(
|
var TestObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 100).Funcs(
|
||||||
func(j *serializertesting.MyWeirdCustomEmbeddedVersionKindField, c fuzz.Continue) {
|
func(j *runtimetesting.MyWeirdCustomEmbeddedVersionKindField, c fuzz.Continue) {
|
||||||
c.FuzzNoCustom(j)
|
c.FuzzNoCustom(j)
|
||||||
j.APIVersion = ""
|
j.APIVersion = ""
|
||||||
j.ObjectKind = ""
|
j.ObjectKind = ""
|
||||||
@ -78,17 +78,17 @@ func GetTestScheme() (*runtime.Scheme, runtime.Codec) {
|
|||||||
// Ordinarily, we wouldn't add TestType2, but because this is a test and
|
// Ordinarily, we wouldn't add TestType2, but because this is a test and
|
||||||
// both types are from the same package, we need to get it into the system
|
// both types are from the same package, we need to get it into the system
|
||||||
// so that converter will match it with ExternalType2.
|
// so that converter will match it with ExternalType2.
|
||||||
s.AddKnownTypes(internalGV, &serializertesting.TestType1{}, &serializertesting.TestType2{}, &serializertesting.ExternalInternalSame{})
|
s.AddKnownTypes(internalGV, &runtimetesting.TestType1{}, &runtimetesting.TestType2{}, &runtimetesting.ExternalInternalSame{})
|
||||||
s.AddKnownTypes(externalGV, &serializertesting.ExternalInternalSame{})
|
s.AddKnownTypes(externalGV, &runtimetesting.ExternalInternalSame{})
|
||||||
s.AddKnownTypeWithName(externalGV.WithKind("TestType1"), &serializertesting.ExternalTestType1{})
|
s.AddKnownTypeWithName(externalGV.WithKind("TestType1"), &runtimetesting.ExternalTestType1{})
|
||||||
s.AddKnownTypeWithName(externalGV.WithKind("TestType2"), &serializertesting.ExternalTestType2{})
|
s.AddKnownTypeWithName(externalGV.WithKind("TestType2"), &runtimetesting.ExternalTestType2{})
|
||||||
s.AddKnownTypeWithName(internalGV.WithKind("TestType3"), &serializertesting.TestType1{})
|
s.AddKnownTypeWithName(internalGV.WithKind("TestType3"), &runtimetesting.TestType1{})
|
||||||
s.AddKnownTypeWithName(externalGV.WithKind("TestType3"), &serializertesting.ExternalTestType1{})
|
s.AddKnownTypeWithName(externalGV.WithKind("TestType3"), &runtimetesting.ExternalTestType1{})
|
||||||
s.AddKnownTypeWithName(externalGV2.WithKind("TestType1"), &serializertesting.ExternalTestType1{})
|
s.AddKnownTypeWithName(externalGV2.WithKind("TestType1"), &runtimetesting.ExternalTestType1{})
|
||||||
|
|
||||||
s.AddUnversionedTypes(externalGV, &metav1.Status{})
|
s.AddUnversionedTypes(externalGV, &metav1.Status{})
|
||||||
|
|
||||||
utilruntime.Must(serializertesting.RegisterConversions(s))
|
utilruntime.Must(runtimetesting.RegisterConversions(s))
|
||||||
|
|
||||||
cf := newCodecFactory(s, newSerializersForScheme(s, testMetaFactory{}, CodecFactoryOptions{Pretty: true, Strict: true}))
|
cf := newCodecFactory(s, newSerializersForScheme(s, testMetaFactory{}, CodecFactoryOptions{Pretty: true, Strict: true}))
|
||||||
codec := cf.LegacyCodec(schema.GroupVersion{Version: "v1"})
|
codec := cf.LegacyCodec(schema.GroupVersion{Version: "v1"})
|
||||||
@ -96,7 +96,7 @@ func GetTestScheme() (*runtime.Scheme, runtime.Codec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var semantic = conversion.EqualitiesOrDie(
|
var semantic = conversion.EqualitiesOrDie(
|
||||||
func(a, b serializertesting.MyWeirdCustomEmbeddedVersionKindField) bool {
|
func(a, b runtimetesting.MyWeirdCustomEmbeddedVersionKindField) bool {
|
||||||
a.APIVersion, a.ObjectKind = "", ""
|
a.APIVersion, a.ObjectKind = "", ""
|
||||||
b.APIVersion, b.ObjectKind = "", ""
|
b.APIVersion, b.ObjectKind = "", ""
|
||||||
return a == b
|
return a == b
|
||||||
@ -135,8 +135,8 @@ func runTest(t *testing.T, source interface{}) {
|
|||||||
|
|
||||||
func TestTypes(t *testing.T) {
|
func TestTypes(t *testing.T) {
|
||||||
table := []interface{}{
|
table := []interface{}{
|
||||||
&serializertesting.TestType1{},
|
&runtimetesting.TestType1{},
|
||||||
&serializertesting.ExternalInternalSame{},
|
&runtimetesting.ExternalInternalSame{},
|
||||||
}
|
}
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
// Try a few times, since runTest uses random values.
|
// Try a few times, since runTest uses random values.
|
||||||
@ -153,7 +153,7 @@ func TestVersionedEncoding(t *testing.T) {
|
|||||||
encoder := info.Serializer
|
encoder := info.Serializer
|
||||||
|
|
||||||
codec := cf.EncoderForVersion(encoder, schema.GroupVersion{Version: "v2"})
|
codec := cf.EncoderForVersion(encoder, schema.GroupVersion{Version: "v2"})
|
||||||
out, err := runtime.Encode(codec, &serializertesting.TestType1{})
|
out, err := runtime.Encode(codec, &runtimetesting.TestType1{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -162,14 +162,14 @@ func TestVersionedEncoding(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
codec = cf.EncoderForVersion(encoder, schema.GroupVersion{Version: "v3"})
|
codec = cf.EncoderForVersion(encoder, schema.GroupVersion{Version: "v3"})
|
||||||
_, err = runtime.Encode(codec, &serializertesting.TestType1{})
|
_, err = runtime.Encode(codec, &runtimetesting.TestType1{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// unversioned encode with no versions is written directly to wire
|
// unversioned encode with no versions is written directly to wire
|
||||||
codec = cf.EncoderForVersion(encoder, runtime.InternalGroupVersioner)
|
codec = cf.EncoderForVersion(encoder, runtime.InternalGroupVersioner)
|
||||||
out, err = runtime.Encode(codec, &serializertesting.TestType1{})
|
out, err = runtime.Encode(codec, &runtimetesting.TestType1{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ func TestMultipleNames(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
internal := obj.(*serializertesting.TestType1)
|
internal := obj.(*runtimetesting.TestType1)
|
||||||
if internal.A != "value" {
|
if internal.A != "value" {
|
||||||
t.Fatalf("unexpected decoded object: %#v", internal)
|
t.Fatalf("unexpected decoded object: %#v", internal)
|
||||||
}
|
}
|
||||||
@ -222,16 +222,16 @@ func TestConvertTypesWhenDefaultNamesMatch(t *testing.T) {
|
|||||||
|
|
||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
// create two names internally, with TestType1 being preferred
|
// create two names internally, with TestType1 being preferred
|
||||||
s.AddKnownTypeWithName(internalGV.WithKind("TestType1"), &serializertesting.TestType1{})
|
s.AddKnownTypeWithName(internalGV.WithKind("TestType1"), &runtimetesting.TestType1{})
|
||||||
s.AddKnownTypeWithName(internalGV.WithKind("OtherType1"), &serializertesting.TestType1{})
|
s.AddKnownTypeWithName(internalGV.WithKind("OtherType1"), &runtimetesting.TestType1{})
|
||||||
// create two names externally, with TestType1 being preferred
|
// create two names externally, with TestType1 being preferred
|
||||||
s.AddKnownTypeWithName(externalGV.WithKind("TestType1"), &serializertesting.ExternalTestType1{})
|
s.AddKnownTypeWithName(externalGV.WithKind("TestType1"), &runtimetesting.ExternalTestType1{})
|
||||||
s.AddKnownTypeWithName(externalGV.WithKind("OtherType1"), &serializertesting.ExternalTestType1{})
|
s.AddKnownTypeWithName(externalGV.WithKind("OtherType1"), &runtimetesting.ExternalTestType1{})
|
||||||
if err := serializertesting.RegisterConversions(s); err != nil {
|
if err := runtimetesting.RegisterConversions(s); err != nil {
|
||||||
t.Fatalf("unexpected error; %v", err)
|
t.Fatalf("unexpected error; %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ext := &serializertesting.ExternalTestType1{}
|
ext := &runtimetesting.ExternalTestType1{}
|
||||||
ext.APIVersion = "v1"
|
ext.APIVersion = "v1"
|
||||||
ext.ObjectKind = "OtherType1"
|
ext.ObjectKind = "OtherType1"
|
||||||
ext.A = "test"
|
ext.A = "test"
|
||||||
@ -239,7 +239,7 @@ func TestConvertTypesWhenDefaultNamesMatch(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
expect := &serializertesting.TestType1{A: "test"}
|
expect := &runtimetesting.TestType1{A: "test"}
|
||||||
|
|
||||||
codec := newCodecFactory(
|
codec := newCodecFactory(
|
||||||
s, newSerializersForScheme(s, testMetaFactory{}, CodecFactoryOptions{Pretty: true, Strict: true}),
|
s, newSerializersForScheme(s, testMetaFactory{}, CodecFactoryOptions{Pretty: true, Strict: true}),
|
||||||
@ -253,7 +253,7 @@ func TestConvertTypesWhenDefaultNamesMatch(t *testing.T) {
|
|||||||
t.Errorf("unexpected object: %#v", obj)
|
t.Errorf("unexpected object: %#v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
into := &serializertesting.TestType1{}
|
into := &runtimetesting.TestType1{}
|
||||||
if err := runtime.DecodeInto(codec, data, into); err != nil {
|
if err := runtime.DecodeInto(codec, data, into); err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -264,13 +264,13 @@ func TestConvertTypesWhenDefaultNamesMatch(t *testing.T) {
|
|||||||
|
|
||||||
func TestEncode_Ptr(t *testing.T) {
|
func TestEncode_Ptr(t *testing.T) {
|
||||||
_, codec := GetTestScheme()
|
_, codec := GetTestScheme()
|
||||||
tt := &serializertesting.TestType1{A: "I am a pointer object"}
|
tt := &runtimetesting.TestType1{A: "I am a pointer object"}
|
||||||
data, err := runtime.Encode(codec, tt)
|
data, err := runtime.Encode(codec, tt)
|
||||||
obj2, err2 := runtime.Decode(codec, data)
|
obj2, err2 := runtime.Decode(codec, data)
|
||||||
if err != nil || err2 != nil {
|
if err != nil || err2 != nil {
|
||||||
t.Fatalf("Failure: '%v' '%v'\n%s", err, err2, data)
|
t.Fatalf("Failure: '%v' '%v'\n%s", err, err2, data)
|
||||||
}
|
}
|
||||||
if _, ok := obj2.(*serializertesting.TestType1); !ok {
|
if _, ok := obj2.(*runtimetesting.TestType1); !ok {
|
||||||
t.Fatalf("Got wrong type")
|
t.Fatalf("Got wrong type")
|
||||||
}
|
}
|
||||||
if !semantic.DeepEqual(obj2, tt) {
|
if !semantic.DeepEqual(obj2, tt) {
|
||||||
@ -293,10 +293,10 @@ func TestBadJSONRejection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
badJSONKindMismatch := []byte(`{"myVersionKey":"v1","myKindKey":"ExternalInternalSame"}`)
|
badJSONKindMismatch := []byte(`{"myVersionKey":"v1","myKindKey":"ExternalInternalSame"}`)
|
||||||
if err := runtime.DecodeInto(codec, badJSONKindMismatch, &serializertesting.TestType1{}); err == nil {
|
if err := runtime.DecodeInto(codec, badJSONKindMismatch, &runtimetesting.TestType1{}); err == nil {
|
||||||
t.Errorf("Kind is set but doesn't match the object type: %s", badJSONKindMismatch)
|
t.Errorf("Kind is set but doesn't match the object type: %s", badJSONKindMismatch)
|
||||||
}
|
}
|
||||||
if err := runtime.DecodeInto(codec, []byte(``), &serializertesting.TestType1{}); err != nil {
|
if err := runtime.DecodeInto(codec, []byte(``), &runtimetesting.TestType1{}); err != nil {
|
||||||
t.Errorf("Should allow empty decode: %v", err)
|
t.Errorf("Should allow empty decode: %v", err)
|
||||||
}
|
}
|
||||||
if _, _, err := codec.Decode([]byte(``), &schema.GroupVersionKind{Kind: "ExternalInternalSame"}, nil); err == nil {
|
if _, _, err := codec.Decode([]byte(``), &schema.GroupVersionKind{Kind: "ExternalInternalSame"}, nil); err == nil {
|
||||||
@ -325,12 +325,12 @@ func GetDirectCodecTestScheme() *runtime.Scheme {
|
|||||||
// Ordinarily, we wouldn't add TestType2, but because this is a test and
|
// Ordinarily, we wouldn't add TestType2, but because this is a test and
|
||||||
// both types are from the same package, we need to get it into the system
|
// both types are from the same package, we need to get it into the system
|
||||||
// so that converter will match it with ExternalType2.
|
// so that converter will match it with ExternalType2.
|
||||||
s.AddKnownTypes(internalGV, &serializertesting.TestType1{})
|
s.AddKnownTypes(internalGV, &runtimetesting.TestType1{})
|
||||||
s.AddKnownTypes(externalGV, &serializertesting.ExternalTestType1{})
|
s.AddKnownTypes(externalGV, &runtimetesting.ExternalTestType1{})
|
||||||
|
|
||||||
s.AddUnversionedTypes(externalGV, &metav1.Status{})
|
s.AddUnversionedTypes(externalGV, &metav1.Status{})
|
||||||
|
|
||||||
utilruntime.Must(serializertesting.RegisterConversions(s))
|
utilruntime.Must(runtimetesting.RegisterConversions(s))
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +346,7 @@ func TestDirectCodec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
directEncoder := df.EncoderForVersion(serializer, ignoredGV)
|
directEncoder := df.EncoderForVersion(serializer, ignoredGV)
|
||||||
directDecoder := df.DecoderToVersion(serializer, ignoredGV)
|
directDecoder := df.DecoderToVersion(serializer, ignoredGV)
|
||||||
out, err := runtime.Encode(directEncoder, &serializertesting.ExternalTestType1{})
|
out, err := runtime.Encode(directEncoder, &runtimetesting.ExternalTestType1{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -357,8 +357,8 @@ func TestDirectCodec(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error on Decode: %v", err)
|
t.Fatalf("error on Decode: %v", err)
|
||||||
}
|
}
|
||||||
e := &serializertesting.ExternalTestType1{
|
e := &runtimetesting.ExternalTestType1{
|
||||||
MyWeirdCustomEmbeddedVersionKindField: serializertesting.MyWeirdCustomEmbeddedVersionKindField{
|
MyWeirdCustomEmbeddedVersionKindField: runtimetesting.MyWeirdCustomEmbeddedVersionKindField{
|
||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
ObjectKind: "ExternalTestType1",
|
ObjectKind: "ExternalTestType1",
|
||||||
},
|
},
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
package(default_visibility = ["//visibility:public"])
|
|
||||||
|
|
||||||
load(
|
|
||||||
"@io_bazel_rules_go//go:def.bzl",
|
|
||||||
"go_library",
|
|
||||||
)
|
|
||||||
|
|
||||||
go_library(
|
|
||||||
name = "go_default_library",
|
|
||||||
srcs = [
|
|
||||||
"conversion.go",
|
|
||||||
"doc.go",
|
|
||||||
"types.go",
|
|
||||||
"zz_generated.deepcopy.go",
|
|
||||||
],
|
|
||||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime/serializer/testing",
|
|
||||||
importpath = "k8s.io/apimachinery/pkg/runtime/serializer/testing",
|
|
||||||
deps = [
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "package-srcs",
|
|
||||||
srcs = glob(["**"]),
|
|
||||||
tags = ["automanaged"],
|
|
||||||
visibility = ["//visibility:private"],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "all-srcs",
|
|
||||||
srcs = [":package-srcs"],
|
|
||||||
tags = ["automanaged"],
|
|
||||||
)
|
|
@ -1,150 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2018 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package testing
|
|
||||||
|
|
||||||
import (
|
|
||||||
"k8s.io/apimachinery/pkg/conversion"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func convertTestType1ToExternalTestType1(in *TestType1, out *ExternalTestType1, s conversion.Scope) error {
|
|
||||||
out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField
|
|
||||||
out.A = in.A
|
|
||||||
out.B = in.B
|
|
||||||
out.C = in.C
|
|
||||||
out.D = in.D
|
|
||||||
out.E = in.E
|
|
||||||
out.F = in.F
|
|
||||||
out.G = in.G
|
|
||||||
out.H = in.H
|
|
||||||
out.I = in.I
|
|
||||||
out.J = in.J
|
|
||||||
out.K = in.K
|
|
||||||
out.L = in.L
|
|
||||||
out.M = in.M
|
|
||||||
if in.N != nil {
|
|
||||||
out.N = make(map[string]ExternalTestType2)
|
|
||||||
for key := range in.N {
|
|
||||||
in, tmp := in.N[key], ExternalTestType2{}
|
|
||||||
if err := convertTestType2ToExternalTestType2(&in, &tmp, s); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
out.N[key] = tmp
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
out.N = nil
|
|
||||||
}
|
|
||||||
if in.O != nil {
|
|
||||||
out.O = new(ExternalTestType2)
|
|
||||||
if err := convertTestType2ToExternalTestType2(in.O, out.O, s); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
out.O = nil
|
|
||||||
}
|
|
||||||
if in.P != nil {
|
|
||||||
out.P = make([]ExternalTestType2, len(in.P))
|
|
||||||
for i := range in.P {
|
|
||||||
if err := convertTestType2ToExternalTestType2(&in.P[i], &out.P[i], s); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertExternalTestType1ToTestType1(in *ExternalTestType1, out *TestType1, s conversion.Scope) error {
|
|
||||||
out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField
|
|
||||||
out.A = in.A
|
|
||||||
out.B = in.B
|
|
||||||
out.C = in.C
|
|
||||||
out.D = in.D
|
|
||||||
out.E = in.E
|
|
||||||
out.F = in.F
|
|
||||||
out.G = in.G
|
|
||||||
out.H = in.H
|
|
||||||
out.I = in.I
|
|
||||||
out.J = in.J
|
|
||||||
out.K = in.K
|
|
||||||
out.L = in.L
|
|
||||||
out.M = in.M
|
|
||||||
if in.N != nil {
|
|
||||||
out.N = make(map[string]TestType2)
|
|
||||||
for key := range in.N {
|
|
||||||
in, tmp := in.N[key], TestType2{}
|
|
||||||
if err := convertExternalTestType2ToTestType2(&in, &tmp, s); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
out.N[key] = tmp
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
out.N = nil
|
|
||||||
}
|
|
||||||
if in.O != nil {
|
|
||||||
out.O = new(TestType2)
|
|
||||||
if err := convertExternalTestType2ToTestType2(in.O, out.O, s); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
out.O = nil
|
|
||||||
}
|
|
||||||
if in.P != nil {
|
|
||||||
out.P = make([]TestType2, len(in.P))
|
|
||||||
for i := range in.P {
|
|
||||||
if err := convertExternalTestType2ToTestType2(&in.P[i], &out.P[i], s); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertTestType2ToExternalTestType2(in *TestType2, out *ExternalTestType2, s conversion.Scope) error {
|
|
||||||
out.A = in.A
|
|
||||||
out.B = in.B
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertExternalTestType2ToTestType2(in *ExternalTestType2, out *TestType2, s conversion.Scope) error {
|
|
||||||
out.A = in.A
|
|
||||||
out.B = in.B
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterConversions(s *runtime.Scheme) error {
|
|
||||||
if err := s.AddConversionFunc((*TestType1)(nil), (*ExternalTestType1)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
|
||||||
return convertTestType1ToExternalTestType1(a.(*TestType1), b.(*ExternalTestType1), scope)
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := s.AddConversionFunc((*ExternalTestType1)(nil), (*TestType1)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
|
||||||
return convertExternalTestType1ToTestType1(a.(*ExternalTestType1), b.(*TestType1), scope)
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := s.AddConversionFunc((*TestType2)(nil), (*ExternalTestType2)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
|
||||||
return convertTestType2ToExternalTestType2(a.(*TestType2), b.(*ExternalTestType2), scope)
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := s.AddConversionFunc((*ExternalTestType2)(nil), (*TestType2)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
|
||||||
return convertExternalTestType2ToTestType2(a.(*ExternalTestType2), b.(*TestType2), scope)
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2014 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// +k8s:deepcopy-gen=package
|
|
||||||
|
|
||||||
package testing // import "k8s.io/apimachinery/pkg/runtime/serializer/testing"
|
|
@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2014 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package testing
|
|
||||||
|
|
||||||
import (
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Test a weird version/kind embedding format.
|
|
||||||
// +k8s:deepcopy-gen=false
|
|
||||||
type MyWeirdCustomEmbeddedVersionKindField struct {
|
|
||||||
ID string `json:"ID,omitempty"`
|
|
||||||
APIVersion string `json:"myVersionKey,omitempty"`
|
|
||||||
ObjectKind string `json:"myKindKey,omitempty"`
|
|
||||||
Z string `json:"Z,omitempty"`
|
|
||||||
Y uint64 `json:"Y,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
type TestType1 struct {
|
|
||||||
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
|
|
||||||
A string `json:"A,omitempty"`
|
|
||||||
B int `json:"B,omitempty"`
|
|
||||||
C int8 `json:"C,omitempty"`
|
|
||||||
D int16 `json:"D,omitempty"`
|
|
||||||
E int32 `json:"E,omitempty"`
|
|
||||||
F int64 `json:"F,omitempty"`
|
|
||||||
G uint `json:"G,omitempty"`
|
|
||||||
H uint8 `json:"H,omitempty"`
|
|
||||||
I uint16 `json:"I,omitempty"`
|
|
||||||
J uint32 `json:"J,omitempty"`
|
|
||||||
K uint64 `json:"K,omitempty"`
|
|
||||||
L bool `json:"L,omitempty"`
|
|
||||||
M map[string]int `json:"M,omitempty"`
|
|
||||||
N map[string]TestType2 `json:"N,omitempty"`
|
|
||||||
O *TestType2 `json:"O,omitempty"`
|
|
||||||
P []TestType2 `json:"Q,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
type TestType2 struct {
|
|
||||||
A string `json:"A,omitempty"`
|
|
||||||
B int `json:"B,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
type ExternalTestType2 struct {
|
|
||||||
A string `json:"A,omitempty"`
|
|
||||||
B int `json:"B,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
type ExternalTestType1 struct {
|
|
||||||
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
|
|
||||||
A string `json:"A,omitempty"`
|
|
||||||
B int `json:"B,omitempty"`
|
|
||||||
C int8 `json:"C,omitempty"`
|
|
||||||
D int16 `json:"D,omitempty"`
|
|
||||||
E int32 `json:"E,omitempty"`
|
|
||||||
F int64 `json:"F,omitempty"`
|
|
||||||
G uint `json:"G,omitempty"`
|
|
||||||
H uint8 `json:"H,omitempty"`
|
|
||||||
I uint16 `json:"I,omitempty"`
|
|
||||||
J uint32 `json:"J,omitempty"`
|
|
||||||
K uint64 `json:"K,omitempty"`
|
|
||||||
L bool `json:"L,omitempty"`
|
|
||||||
M map[string]int `json:"M,omitempty"`
|
|
||||||
N map[string]ExternalTestType2 `json:"N,omitempty"`
|
|
||||||
O *ExternalTestType2 `json:"O,omitempty"`
|
|
||||||
P []ExternalTestType2 `json:"Q,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
type ExternalInternalSame struct {
|
|
||||||
MyWeirdCustomEmbeddedVersionKindField `json:",inline"`
|
|
||||||
A TestType2 `json:"A,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (obj *MyWeirdCustomEmbeddedVersionKindField) GetObjectKind() schema.ObjectKind { return obj }
|
|
||||||
func (obj *MyWeirdCustomEmbeddedVersionKindField) SetGroupVersionKind(gvk schema.GroupVersionKind) {
|
|
||||||
obj.APIVersion, obj.ObjectKind = gvk.ToAPIVersionAndKind()
|
|
||||||
}
|
|
||||||
func (obj *MyWeirdCustomEmbeddedVersionKindField) GroupVersionKind() schema.GroupVersionKind {
|
|
||||||
return schema.FromAPIVersionAndKind(obj.APIVersion, obj.ObjectKind)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (obj *ExternalInternalSame) GetObjectKind() schema.ObjectKind {
|
|
||||||
return &obj.MyWeirdCustomEmbeddedVersionKindField
|
|
||||||
}
|
|
||||||
|
|
||||||
func (obj *TestType1) GetObjectKind() schema.ObjectKind {
|
|
||||||
return &obj.MyWeirdCustomEmbeddedVersionKindField
|
|
||||||
}
|
|
||||||
|
|
||||||
func (obj *ExternalTestType1) GetObjectKind() schema.ObjectKind {
|
|
||||||
return &obj.MyWeirdCustomEmbeddedVersionKindField
|
|
||||||
}
|
|
||||||
|
|
||||||
func (obj *TestType2) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
|
|
||||||
func (obj *ExternalTestType2) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
|
|
@ -1,197 +0,0 @@
|
|||||||
// +build !ignore_autogenerated
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by deepcopy-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package testing
|
|
||||||
|
|
||||||
import (
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *ExternalInternalSame) DeepCopyInto(out *ExternalInternalSame) {
|
|
||||||
*out = *in
|
|
||||||
out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField
|
|
||||||
out.A = in.A
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalInternalSame.
|
|
||||||
func (in *ExternalInternalSame) DeepCopy() *ExternalInternalSame {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(ExternalInternalSame)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *ExternalInternalSame) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *ExternalTestType1) DeepCopyInto(out *ExternalTestType1) {
|
|
||||||
*out = *in
|
|
||||||
out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField
|
|
||||||
if in.M != nil {
|
|
||||||
in, out := &in.M, &out.M
|
|
||||||
*out = make(map[string]int, len(*in))
|
|
||||||
for key, val := range *in {
|
|
||||||
(*out)[key] = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if in.N != nil {
|
|
||||||
in, out := &in.N, &out.N
|
|
||||||
*out = make(map[string]ExternalTestType2, len(*in))
|
|
||||||
for key, val := range *in {
|
|
||||||
(*out)[key] = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if in.O != nil {
|
|
||||||
in, out := &in.O, &out.O
|
|
||||||
*out = new(ExternalTestType2)
|
|
||||||
**out = **in
|
|
||||||
}
|
|
||||||
if in.P != nil {
|
|
||||||
in, out := &in.P, &out.P
|
|
||||||
*out = make([]ExternalTestType2, len(*in))
|
|
||||||
copy(*out, *in)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalTestType1.
|
|
||||||
func (in *ExternalTestType1) DeepCopy() *ExternalTestType1 {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(ExternalTestType1)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *ExternalTestType1) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *ExternalTestType2) DeepCopyInto(out *ExternalTestType2) {
|
|
||||||
*out = *in
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalTestType2.
|
|
||||||
func (in *ExternalTestType2) DeepCopy() *ExternalTestType2 {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(ExternalTestType2)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *ExternalTestType2) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *TestType1) DeepCopyInto(out *TestType1) {
|
|
||||||
*out = *in
|
|
||||||
out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField
|
|
||||||
if in.M != nil {
|
|
||||||
in, out := &in.M, &out.M
|
|
||||||
*out = make(map[string]int, len(*in))
|
|
||||||
for key, val := range *in {
|
|
||||||
(*out)[key] = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if in.N != nil {
|
|
||||||
in, out := &in.N, &out.N
|
|
||||||
*out = make(map[string]TestType2, len(*in))
|
|
||||||
for key, val := range *in {
|
|
||||||
(*out)[key] = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if in.O != nil {
|
|
||||||
in, out := &in.O, &out.O
|
|
||||||
*out = new(TestType2)
|
|
||||||
**out = **in
|
|
||||||
}
|
|
||||||
if in.P != nil {
|
|
||||||
in, out := &in.P, &out.P
|
|
||||||
*out = make([]TestType2, len(*in))
|
|
||||||
copy(*out, *in)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType1.
|
|
||||||
func (in *TestType1) DeepCopy() *TestType1 {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(TestType1)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *TestType1) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *TestType2) DeepCopyInto(out *TestType2) {
|
|
||||||
*out = *in
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType2.
|
|
||||||
func (in *TestType2) DeepCopy() *TestType2 {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(TestType2)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *TestType2) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -9,6 +9,7 @@ go_library(
|
|||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"cacheable_object.go",
|
"cacheable_object.go",
|
||||||
|
"conversion.go",
|
||||||
"doc.go",
|
"doc.go",
|
||||||
"types.go",
|
"types.go",
|
||||||
"zz_generated.deepcopy.go",
|
"zz_generated.deepcopy.go",
|
||||||
@ -16,6 +17,7 @@ go_library(
|
|||||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime/testing",
|
importmap = "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime/testing",
|
||||||
importpath = "k8s.io/apimachinery/pkg/runtime/testing",
|
importpath = "k8s.io/apimachinery/pkg/runtime/testing",
|
||||||
deps = [
|
deps = [
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/json:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/json:go_default_library",
|
||||||
|
@ -0,0 +1,300 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/conversion"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func convertEmbeddedTestToEmbeddedTestExternal(in *EmbeddedTest, out *EmbeddedTestExternal, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
out.ID = in.ID
|
||||||
|
if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Object, &out.Object, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.EmptyObject, &out.EmptyObject, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertEmbeddedTestExternalToEmbeddedTest(in *EmbeddedTestExternal, out *EmbeddedTest, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
out.ID = in.ID
|
||||||
|
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Object, &out.Object, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.EmptyObject, &out.EmptyObject, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertObjectTestToObjectTestExternal(in *ObjectTest, out *ObjectTestExternal, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
out.ID = in.ID
|
||||||
|
if in.Items != nil {
|
||||||
|
out.Items = make([]runtime.RawExtension, len(in.Items))
|
||||||
|
for i := range in.Items {
|
||||||
|
if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Items[i], &out.Items[i], s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.Items = nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertObjectTestExternalToObjectTest(in *ObjectTestExternal, out *ObjectTest, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
out.ID = in.ID
|
||||||
|
if in.Items != nil {
|
||||||
|
out.Items = make([]runtime.Object, len(in.Items))
|
||||||
|
for i := range in.Items {
|
||||||
|
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Items[i], &out.Items[i], s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.Items = nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertInternalSimpleToExternalSimple(in *InternalSimple, out *ExternalSimple, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
out.TestString = in.TestString
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertExternalSimpleToInternalSimple(in *ExternalSimple, out *InternalSimple, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
out.TestString = in.TestString
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertInternalExtensionTypeToExternalExtensionType(in *InternalExtensionType, out *ExternalExtensionType, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Extension, &out.Extension, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertExternalExtensionTypeToInternalExtensionType(in *ExternalExtensionType, out *InternalExtensionType, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Extension, &out.Extension, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertInternalOptionalExtensionTypeToExternalOptionalExtensionType(in *InternalOptionalExtensionType, out *ExternalOptionalExtensionType, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Extension, &out.Extension, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertExternalOptionalExtensionTypeToInternalOptionalExtensionType(in *ExternalOptionalExtensionType, out *InternalOptionalExtensionType, s conversion.Scope) error {
|
||||||
|
out.TypeMeta = in.TypeMeta
|
||||||
|
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Extension, &out.Extension, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertTestType1ToExternalTestType1(in *TestType1, out *ExternalTestType1, s conversion.Scope) error {
|
||||||
|
out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField
|
||||||
|
out.A = in.A
|
||||||
|
out.B = in.B
|
||||||
|
out.C = in.C
|
||||||
|
out.D = in.D
|
||||||
|
out.E = in.E
|
||||||
|
out.F = in.F
|
||||||
|
out.G = in.G
|
||||||
|
out.H = in.H
|
||||||
|
out.I = in.I
|
||||||
|
out.J = in.J
|
||||||
|
out.K = in.K
|
||||||
|
out.L = in.L
|
||||||
|
out.M = in.M
|
||||||
|
if in.N != nil {
|
||||||
|
out.N = make(map[string]ExternalTestType2)
|
||||||
|
for key := range in.N {
|
||||||
|
in, tmp := in.N[key], ExternalTestType2{}
|
||||||
|
if err := convertTestType2ToExternalTestType2(&in, &tmp, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out.N[key] = tmp
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.N = nil
|
||||||
|
}
|
||||||
|
if in.O != nil {
|
||||||
|
out.O = new(ExternalTestType2)
|
||||||
|
if err := convertTestType2ToExternalTestType2(in.O, out.O, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.O = nil
|
||||||
|
}
|
||||||
|
if in.P != nil {
|
||||||
|
out.P = make([]ExternalTestType2, len(in.P))
|
||||||
|
for i := range in.P {
|
||||||
|
if err := convertTestType2ToExternalTestType2(&in.P[i], &out.P[i], s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertExternalTestType1ToTestType1(in *ExternalTestType1, out *TestType1, s conversion.Scope) error {
|
||||||
|
out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField
|
||||||
|
out.A = in.A
|
||||||
|
out.B = in.B
|
||||||
|
out.C = in.C
|
||||||
|
out.D = in.D
|
||||||
|
out.E = in.E
|
||||||
|
out.F = in.F
|
||||||
|
out.G = in.G
|
||||||
|
out.H = in.H
|
||||||
|
out.I = in.I
|
||||||
|
out.J = in.J
|
||||||
|
out.K = in.K
|
||||||
|
out.L = in.L
|
||||||
|
out.M = in.M
|
||||||
|
if in.N != nil {
|
||||||
|
out.N = make(map[string]TestType2)
|
||||||
|
for key := range in.N {
|
||||||
|
in, tmp := in.N[key], TestType2{}
|
||||||
|
if err := convertExternalTestType2ToTestType2(&in, &tmp, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out.N[key] = tmp
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.N = nil
|
||||||
|
}
|
||||||
|
if in.O != nil {
|
||||||
|
out.O = new(TestType2)
|
||||||
|
if err := convertExternalTestType2ToTestType2(in.O, out.O, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.O = nil
|
||||||
|
}
|
||||||
|
if in.P != nil {
|
||||||
|
out.P = make([]TestType2, len(in.P))
|
||||||
|
for i := range in.P {
|
||||||
|
if err := convertExternalTestType2ToTestType2(&in.P[i], &out.P[i], s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertTestType2ToExternalTestType2(in *TestType2, out *ExternalTestType2, s conversion.Scope) error {
|
||||||
|
out.A = in.A
|
||||||
|
out.B = in.B
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertExternalTestType2ToTestType2(in *ExternalTestType2, out *TestType2, s conversion.Scope) error {
|
||||||
|
out.A = in.A
|
||||||
|
out.B = in.B
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterConversions(s *runtime.Scheme) error {
|
||||||
|
if err := s.AddConversionFunc((*EmbeddedTest)(nil), (*EmbeddedTestExternal)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertEmbeddedTestToEmbeddedTestExternal(a.(*EmbeddedTest), b.(*EmbeddedTestExternal), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*EmbeddedTestExternal)(nil), (*EmbeddedTest)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertEmbeddedTestExternalToEmbeddedTest(a.(*EmbeddedTestExternal), b.(*EmbeddedTest), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*ObjectTest)(nil), (*ObjectTestExternal)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertObjectTestToObjectTestExternal(a.(*ObjectTest), b.(*ObjectTestExternal), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*ObjectTestExternal)(nil), (*ObjectTest)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertObjectTestExternalToObjectTest(a.(*ObjectTestExternal), b.(*ObjectTest), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*InternalSimple)(nil), (*ExternalSimple)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertInternalSimpleToExternalSimple(a.(*InternalSimple), b.(*ExternalSimple), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*ExternalSimple)(nil), (*InternalSimple)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertExternalSimpleToInternalSimple(a.(*ExternalSimple), b.(*InternalSimple), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*InternalExtensionType)(nil), (*ExternalExtensionType)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertInternalExtensionTypeToExternalExtensionType(a.(*InternalExtensionType), b.(*ExternalExtensionType), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*ExternalExtensionType)(nil), (*InternalExtensionType)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertExternalExtensionTypeToInternalExtensionType(a.(*ExternalExtensionType), b.(*InternalExtensionType), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*InternalOptionalExtensionType)(nil), (*ExternalOptionalExtensionType)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertInternalOptionalExtensionTypeToExternalOptionalExtensionType(a.(*InternalOptionalExtensionType), b.(*ExternalOptionalExtensionType), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*ExternalOptionalExtensionType)(nil), (*InternalOptionalExtensionType)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertExternalOptionalExtensionTypeToInternalOptionalExtensionType(a.(*ExternalOptionalExtensionType), b.(*InternalOptionalExtensionType), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*TestType1)(nil), (*ExternalTestType1)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertTestType1ToExternalTestType1(a.(*TestType1), b.(*ExternalTestType1), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*ExternalTestType1)(nil), (*TestType1)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertExternalTestType1ToTestType1(a.(*ExternalTestType1), b.(*TestType1), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*TestType2)(nil), (*ExternalTestType2)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertTestType2ToExternalTestType2(a.(*TestType2), b.(*ExternalTestType2), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*ExternalTestType2)(nil), (*TestType2)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return convertExternalTestType2ToTestType2(a.(*ExternalTestType2), b.(*TestType2), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user