github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/runtime/testing/conversion.go (about)

     1  /*
     2  Copyright 2020 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package testing
    18  
    19  import (
    20  	"github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/conversion"
    21  	"github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/runtime"
    22  )
    23  
    24  func convertEmbeddedTestToEmbeddedTestExternal(in *EmbeddedTest, out *EmbeddedTestExternal, s conversion.Scope) error {
    25  	out.TypeMeta = in.TypeMeta
    26  	out.ID = in.ID
    27  	if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Object, &out.Object, s); err != nil {
    28  		return err
    29  	}
    30  	if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.EmptyObject, &out.EmptyObject, s); err != nil {
    31  		return err
    32  	}
    33  	return nil
    34  }
    35  
    36  func convertEmbeddedTestExternalToEmbeddedTest(in *EmbeddedTestExternal, out *EmbeddedTest, s conversion.Scope) error {
    37  	out.TypeMeta = in.TypeMeta
    38  	out.ID = in.ID
    39  	if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Object, &out.Object, s); err != nil {
    40  		return err
    41  	}
    42  	if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.EmptyObject, &out.EmptyObject, s); err != nil {
    43  		return err
    44  	}
    45  	return nil
    46  }
    47  
    48  func convertObjectTestToObjectTestExternal(in *ObjectTest, out *ObjectTestExternal, s conversion.Scope) error {
    49  	out.TypeMeta = in.TypeMeta
    50  	out.ID = in.ID
    51  	if in.Items != nil {
    52  		out.Items = make([]runtime.RawExtension, len(in.Items))
    53  		for i := range in.Items {
    54  			if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Items[i], &out.Items[i], s); err != nil {
    55  				return err
    56  			}
    57  		}
    58  	} else {
    59  		out.Items = nil
    60  	}
    61  	return nil
    62  }
    63  
    64  func convertObjectTestExternalToObjectTest(in *ObjectTestExternal, out *ObjectTest, s conversion.Scope) error {
    65  	out.TypeMeta = in.TypeMeta
    66  	out.ID = in.ID
    67  	if in.Items != nil {
    68  		out.Items = make([]runtime.Object, len(in.Items))
    69  		for i := range in.Items {
    70  			if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Items[i], &out.Items[i], s); err != nil {
    71  				return err
    72  			}
    73  		}
    74  	} else {
    75  		out.Items = nil
    76  	}
    77  	return nil
    78  }
    79  
    80  func convertInternalSimpleToExternalSimple(in *InternalSimple, out *ExternalSimple, s conversion.Scope) error {
    81  	out.TypeMeta = in.TypeMeta
    82  	out.TestString = in.TestString
    83  	return nil
    84  }
    85  
    86  func convertExternalSimpleToInternalSimple(in *ExternalSimple, out *InternalSimple, s conversion.Scope) error {
    87  	out.TypeMeta = in.TypeMeta
    88  	out.TestString = in.TestString
    89  	return nil
    90  }
    91  
    92  func convertInternalExtensionTypeToExternalExtensionType(in *InternalExtensionType, out *ExternalExtensionType, s conversion.Scope) error {
    93  	out.TypeMeta = in.TypeMeta
    94  	if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Extension, &out.Extension, s); err != nil {
    95  		return err
    96  	}
    97  	return nil
    98  }
    99  
   100  func convertExternalExtensionTypeToInternalExtensionType(in *ExternalExtensionType, out *InternalExtensionType, s conversion.Scope) error {
   101  	out.TypeMeta = in.TypeMeta
   102  	if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Extension, &out.Extension, s); err != nil {
   103  		return err
   104  	}
   105  	return nil
   106  }
   107  
   108  func convertInternalOptionalExtensionTypeToExternalOptionalExtensionType(in *InternalOptionalExtensionType, out *ExternalOptionalExtensionType, s conversion.Scope) error {
   109  	out.TypeMeta = in.TypeMeta
   110  	if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Extension, &out.Extension, s); err != nil {
   111  		return err
   112  	}
   113  	return nil
   114  }
   115  
   116  func convertExternalOptionalExtensionTypeToInternalOptionalExtensionType(in *ExternalOptionalExtensionType, out *InternalOptionalExtensionType, s conversion.Scope) error {
   117  	out.TypeMeta = in.TypeMeta
   118  	if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Extension, &out.Extension, s); err != nil {
   119  		return err
   120  	}
   121  	return nil
   122  }
   123  
   124  func convertTestType1ToExternalTestType1(in *TestType1, out *ExternalTestType1, s conversion.Scope) error {
   125  	out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField
   126  	out.A = in.A
   127  	out.B = in.B
   128  	out.C = in.C
   129  	out.D = in.D
   130  	out.E = in.E
   131  	out.F = in.F
   132  	out.G = in.G
   133  	out.H = in.H
   134  	out.I = in.I
   135  	out.J = in.J
   136  	out.K = in.K
   137  	out.L = in.L
   138  	out.M = in.M
   139  	if in.N != nil {
   140  		out.N = make(map[string]ExternalTestType2)
   141  		for key := range in.N {
   142  			in, tmp := in.N[key], ExternalTestType2{}
   143  			if err := convertTestType2ToExternalTestType2(&in, &tmp, s); err != nil {
   144  				return err
   145  			}
   146  			out.N[key] = tmp
   147  		}
   148  	} else {
   149  		out.N = nil
   150  	}
   151  	if in.O != nil {
   152  		out.O = new(ExternalTestType2)
   153  		if err := convertTestType2ToExternalTestType2(in.O, out.O, s); err != nil {
   154  			return err
   155  		}
   156  	} else {
   157  		out.O = nil
   158  	}
   159  	if in.P != nil {
   160  		out.P = make([]ExternalTestType2, len(in.P))
   161  		for i := range in.P {
   162  			if err := convertTestType2ToExternalTestType2(&in.P[i], &out.P[i], s); err != nil {
   163  				return err
   164  			}
   165  		}
   166  	}
   167  	return nil
   168  }
   169  
   170  func convertExternalTestType1ToTestType1(in *ExternalTestType1, out *TestType1, s conversion.Scope) error {
   171  	out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField
   172  	out.A = in.A
   173  	out.B = in.B
   174  	out.C = in.C
   175  	out.D = in.D
   176  	out.E = in.E
   177  	out.F = in.F
   178  	out.G = in.G
   179  	out.H = in.H
   180  	out.I = in.I
   181  	out.J = in.J
   182  	out.K = in.K
   183  	out.L = in.L
   184  	out.M = in.M
   185  	if in.N != nil {
   186  		out.N = make(map[string]TestType2)
   187  		for key := range in.N {
   188  			in, tmp := in.N[key], TestType2{}
   189  			if err := convertExternalTestType2ToTestType2(&in, &tmp, s); err != nil {
   190  				return err
   191  			}
   192  			out.N[key] = tmp
   193  		}
   194  	} else {
   195  		out.N = nil
   196  	}
   197  	if in.O != nil {
   198  		out.O = new(TestType2)
   199  		if err := convertExternalTestType2ToTestType2(in.O, out.O, s); err != nil {
   200  			return err
   201  		}
   202  	} else {
   203  		out.O = nil
   204  	}
   205  	if in.P != nil {
   206  		out.P = make([]TestType2, len(in.P))
   207  		for i := range in.P {
   208  			if err := convertExternalTestType2ToTestType2(&in.P[i], &out.P[i], s); err != nil {
   209  				return err
   210  			}
   211  		}
   212  	}
   213  	return nil
   214  }
   215  
   216  func convertTestType2ToExternalTestType2(in *TestType2, out *ExternalTestType2, s conversion.Scope) error {
   217  	out.A = in.A
   218  	out.B = in.B
   219  	return nil
   220  }
   221  
   222  func convertExternalTestType2ToTestType2(in *ExternalTestType2, out *TestType2, s conversion.Scope) error {
   223  	out.A = in.A
   224  	out.B = in.B
   225  	return nil
   226  }
   227  
   228  func RegisterConversions(s *runtime.Scheme) error {
   229  	if err := s.AddConversionFunc((*EmbeddedTest)(nil), (*EmbeddedTestExternal)(nil), func(a, b interface{}, scope conversion.Scope) error {
   230  		return convertEmbeddedTestToEmbeddedTestExternal(a.(*EmbeddedTest), b.(*EmbeddedTestExternal), scope)
   231  	}); err != nil {
   232  		return err
   233  	}
   234  	if err := s.AddConversionFunc((*EmbeddedTestExternal)(nil), (*EmbeddedTest)(nil), func(a, b interface{}, scope conversion.Scope) error {
   235  		return convertEmbeddedTestExternalToEmbeddedTest(a.(*EmbeddedTestExternal), b.(*EmbeddedTest), scope)
   236  	}); err != nil {
   237  		return err
   238  	}
   239  	if err := s.AddConversionFunc((*ObjectTest)(nil), (*ObjectTestExternal)(nil), func(a, b interface{}, scope conversion.Scope) error {
   240  		return convertObjectTestToObjectTestExternal(a.(*ObjectTest), b.(*ObjectTestExternal), scope)
   241  	}); err != nil {
   242  		return err
   243  	}
   244  	if err := s.AddConversionFunc((*ObjectTestExternal)(nil), (*ObjectTest)(nil), func(a, b interface{}, scope conversion.Scope) error {
   245  		return convertObjectTestExternalToObjectTest(a.(*ObjectTestExternal), b.(*ObjectTest), scope)
   246  	}); err != nil {
   247  		return err
   248  	}
   249  	if err := s.AddConversionFunc((*InternalSimple)(nil), (*ExternalSimple)(nil), func(a, b interface{}, scope conversion.Scope) error {
   250  		return convertInternalSimpleToExternalSimple(a.(*InternalSimple), b.(*ExternalSimple), scope)
   251  	}); err != nil {
   252  		return err
   253  	}
   254  	if err := s.AddConversionFunc((*ExternalSimple)(nil), (*InternalSimple)(nil), func(a, b interface{}, scope conversion.Scope) error {
   255  		return convertExternalSimpleToInternalSimple(a.(*ExternalSimple), b.(*InternalSimple), scope)
   256  	}); err != nil {
   257  		return err
   258  	}
   259  	if err := s.AddConversionFunc((*InternalExtensionType)(nil), (*ExternalExtensionType)(nil), func(a, b interface{}, scope conversion.Scope) error {
   260  		return convertInternalExtensionTypeToExternalExtensionType(a.(*InternalExtensionType), b.(*ExternalExtensionType), scope)
   261  	}); err != nil {
   262  		return err
   263  	}
   264  	if err := s.AddConversionFunc((*ExternalExtensionType)(nil), (*InternalExtensionType)(nil), func(a, b interface{}, scope conversion.Scope) error {
   265  		return convertExternalExtensionTypeToInternalExtensionType(a.(*ExternalExtensionType), b.(*InternalExtensionType), scope)
   266  	}); err != nil {
   267  		return err
   268  	}
   269  	if err := s.AddConversionFunc((*InternalOptionalExtensionType)(nil), (*ExternalOptionalExtensionType)(nil), func(a, b interface{}, scope conversion.Scope) error {
   270  		return convertInternalOptionalExtensionTypeToExternalOptionalExtensionType(a.(*InternalOptionalExtensionType), b.(*ExternalOptionalExtensionType), scope)
   271  	}); err != nil {
   272  		return err
   273  	}
   274  	if err := s.AddConversionFunc((*ExternalOptionalExtensionType)(nil), (*InternalOptionalExtensionType)(nil), func(a, b interface{}, scope conversion.Scope) error {
   275  		return convertExternalOptionalExtensionTypeToInternalOptionalExtensionType(a.(*ExternalOptionalExtensionType), b.(*InternalOptionalExtensionType), scope)
   276  	}); err != nil {
   277  		return err
   278  	}
   279  	if err := s.AddConversionFunc((*TestType1)(nil), (*ExternalTestType1)(nil), func(a, b interface{}, scope conversion.Scope) error {
   280  		return convertTestType1ToExternalTestType1(a.(*TestType1), b.(*ExternalTestType1), scope)
   281  	}); err != nil {
   282  		return err
   283  	}
   284  	if err := s.AddConversionFunc((*ExternalTestType1)(nil), (*TestType1)(nil), func(a, b interface{}, scope conversion.Scope) error {
   285  		return convertExternalTestType1ToTestType1(a.(*ExternalTestType1), b.(*TestType1), scope)
   286  	}); err != nil {
   287  		return err
   288  	}
   289  	if err := s.AddConversionFunc((*TestType2)(nil), (*ExternalTestType2)(nil), func(a, b interface{}, scope conversion.Scope) error {
   290  		return convertTestType2ToExternalTestType2(a.(*TestType2), b.(*ExternalTestType2), scope)
   291  	}); err != nil {
   292  		return err
   293  	}
   294  	if err := s.AddConversionFunc((*ExternalTestType2)(nil), (*TestType2)(nil), func(a, b interface{}, scope conversion.Scope) error {
   295  		return convertExternalTestType2ToTestType2(a.(*ExternalTestType2), b.(*TestType2), scope)
   296  	}); err != nil {
   297  		return err
   298  	}
   299  	return nil
   300  }