diff --git a/cmd/libs/go2idl/conversion-gen/main.go b/cmd/libs/go2idl/conversion-gen/main.go index 47dee55b0ef57..489cbbf5a972b 100644 --- a/cmd/libs/go2idl/conversion-gen/main.go +++ b/cmd/libs/go2idl/conversion-gen/main.go @@ -35,6 +35,7 @@ func main() { arguments.InputDirs = []string{ "k8s.io/kubernetes/pkg/api/v1", "k8s.io/kubernetes/pkg/api", + "k8s.io/kubernetes/pkg/conversion", "k8s.io/kubernetes/pkg/runtime", } diff --git a/pkg/api/conversion.go b/pkg/api/conversion.go index e0605fa098e78..896aef9617e6e 100644 --- a/pkg/api/conversion.go +++ b/pkg/api/conversion.go @@ -41,20 +41,20 @@ func init() { Convert_unversioned_ListMeta_To_unversioned_ListMeta, Convert_intstr_IntOrString_To_intstr_IntOrString, Convert_unversioned_Time_To_unversioned_Time, - Convert_string_slice_To_unversioned_Time, + Convert_Slice_string_To_unversioned_Time, Convert_string_To_labels_Selector, Convert_string_To_fields_Selector, - Convert_bool_ref_To_bool, - Convert_bool_To_bool_ref, - Convert_string_ref_To_string, - Convert_string_To_string_ref, + Convert_Pointer_bool_To_bool, + Convert_bool_To_Pointer_bool, + Convert_Pointer_string_To_string, + Convert_string_To_Pointer_string, Convert_labels_Selector_To_string, Convert_fields_Selector_To_string, Convert_resource_Quantity_To_resource_Quantity, ) } -func Convert_string_ref_To_string(in **string, out *string, s conversion.Scope) error { +func Convert_Pointer_string_To_string(in **string, out *string, s conversion.Scope) error { if *in == nil { *out = "" return nil @@ -63,7 +63,7 @@ func Convert_string_ref_To_string(in **string, out *string, s conversion.Scope) return nil } -func Convert_string_To_string_ref(in *string, out **string, s conversion.Scope) error { +func Convert_string_To_Pointer_string(in *string, out **string, s conversion.Scope) error { if in == nil { stringVar := "" *out = &stringVar @@ -73,7 +73,7 @@ func Convert_string_To_string_ref(in *string, out **string, s conversion.Scope) return nil } -func Convert_bool_ref_To_bool(in **bool, out *bool, s conversion.Scope) error { +func Convert_Pointer_bool_To_bool(in **bool, out *bool, s conversion.Scope) error { if *in == nil { *out = false return nil @@ -82,7 +82,7 @@ func Convert_bool_ref_To_bool(in **bool, out *bool, s conversion.Scope) error { return nil } -func Convert_bool_To_bool_ref(in *bool, out **bool, s conversion.Scope) error { +func Convert_bool_To_Pointer_bool(in *bool, out **bool, s conversion.Scope) error { if in == nil { boolVar := false *out = &boolVar @@ -118,8 +118,8 @@ func Convert_unversioned_Time_To_unversioned_Time(in *unversioned.Time, out *unv return nil } -// Convert_string_slice_To_unversioned_Time allows converting a URL query parameter value -func Convert_string_slice_To_unversioned_Time(input *[]string, out *unversioned.Time, s conversion.Scope) error { +// Convert_Slice_string_To_unversioned_Time allows converting a URL query parameter value +func Convert_Slice_string_To_unversioned_Time(input *[]string, out *unversioned.Time, s conversion.Scope) error { str := "" if len(*input) > 0 { str = (*input)[0] diff --git a/pkg/api/v1/conversion_generated.go b/pkg/api/v1/conversion_generated.go index 107323fb113d5..6be8cf507e19c 100644 --- a/pkg/api/v1/conversion_generated.go +++ b/pkg/api/v1/conversion_generated.go @@ -5805,12 +5805,8 @@ func autoConvert_v1_RangeAllocation_To_api_RangeAllocation(in *RangeAllocation, return err } out.Range = in.Range - if in.Data != nil { - in, out := &in.Data, &out.Data - *out = make([]byte, len(*in)) - copy(*out, *in) - } else { - out.Data = nil + if err := conversion.Convert_Slice_byte_To_Slice_byte(&in.Data, &out.Data, s); err != nil { + return err } return nil } @@ -5830,12 +5826,8 @@ func autoConvert_api_RangeAllocation_To_v1_RangeAllocation(in *api.RangeAllocati return err } out.Range = in.Range - if in.Data != nil { - in, out := &in.Data, &out.Data - *out = make([]byte, len(*in)) - copy(*out, *in) - } else { - out.Data = nil + if err := conversion.Convert_Slice_byte_To_Slice_byte(&in.Data, &out.Data, s); err != nil { + return err } return nil } @@ -6285,8 +6277,7 @@ func autoConvert_v1_Secret_To_api_Secret(in *Secret, out *api.Secret, s conversi *out = make(map[string][]byte, len(*in)) for key, val := range *in { newVal := new([]byte) - // TODO: Inefficient conversion - can we improve it? - if err := s.Convert(&val, newVal, 0); err != nil { + if err := conversion.Convert_Slice_byte_To_Slice_byte(&val, newVal, s); err != nil { return err } (*out)[key] = *newVal @@ -6317,8 +6308,7 @@ func autoConvert_api_Secret_To_v1_Secret(in *api.Secret, out *Secret, s conversi *out = make(map[string][]byte, len(*in)) for key, val := range *in { newVal := new([]byte) - // TODO: Inefficient conversion - can we improve it? - if err := s.Convert(&val, newVal, 0); err != nil { + if err := conversion.Convert_Slice_byte_To_Slice_byte(&val, newVal, s); err != nil { return err } (*out)[key] = *newVal diff --git a/pkg/apis/componentconfig/v1alpha1/conversion_generated.go b/pkg/apis/componentconfig/v1alpha1/conversion_generated.go index b4bff5c816dfb..9a5ce35ee571f 100644 --- a/pkg/apis/componentconfig/v1alpha1/conversion_generated.go +++ b/pkg/apis/componentconfig/v1alpha1/conversion_generated.go @@ -83,7 +83,7 @@ func autoConvert_componentconfig_KubeSchedulerConfiguration_To_v1alpha1_KubeSche out.Address = in.Address out.AlgorithmProvider = in.AlgorithmProvider out.PolicyConfigFile = in.PolicyConfigFile - if err := api.Convert_bool_To_bool_ref(&in.EnableProfiling, &out.EnableProfiling, s); err != nil { + if err := api.Convert_bool_To_Pointer_bool(&in.EnableProfiling, &out.EnableProfiling, s); err != nil { return err } out.KubeAPIQPS = in.KubeAPIQPS @@ -103,7 +103,7 @@ func autoConvert_componentconfig_LeaderElectionConfiguration_To_v1alpha1_LeaderE if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { defaulting.(func(*componentconfig.LeaderElectionConfiguration))(in) } - if err := api.Convert_bool_To_bool_ref(&in.LeaderElect, &out.LeaderElect, s); err != nil { + if err := api.Convert_bool_To_Pointer_bool(&in.LeaderElect, &out.LeaderElect, s); err != nil { return err } if err := s.Convert(&in.LeaseDuration, &out.LeaseDuration, 0); err != nil { @@ -179,7 +179,7 @@ func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_componentconfig_KubeSche out.Address = in.Address out.AlgorithmProvider = in.AlgorithmProvider out.PolicyConfigFile = in.PolicyConfigFile - if err := api.Convert_bool_ref_To_bool(&in.EnableProfiling, &out.EnableProfiling, s); err != nil { + if err := api.Convert_Pointer_bool_To_bool(&in.EnableProfiling, &out.EnableProfiling, s); err != nil { return err } out.KubeAPIQPS = in.KubeAPIQPS @@ -199,7 +199,7 @@ func autoConvert_v1alpha1_LeaderElectionConfiguration_To_componentconfig_LeaderE if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { defaulting.(func(*LeaderElectionConfiguration))(in) } - if err := api.Convert_bool_ref_To_bool(&in.LeaderElect, &out.LeaderElect, s); err != nil { + if err := api.Convert_Pointer_bool_To_bool(&in.LeaderElect, &out.LeaderElect, s); err != nil { return err } if err := s.Convert(&in.LeaseDuration, &out.LeaseDuration, 0); err != nil { diff --git a/pkg/apis/extensions/v1beta1/conversion_generated.go b/pkg/apis/extensions/v1beta1/conversion_generated.go index 88a7aeaf920bd..9d870935fcb0f 100644 --- a/pkg/apis/extensions/v1beta1/conversion_generated.go +++ b/pkg/apis/extensions/v1beta1/conversion_generated.go @@ -3797,7 +3797,7 @@ func autoConvert_extensions_ThirdPartyResourceData_To_v1beta1_ThirdPartyResource if err := Convert_api_ObjectMeta_To_v1_ObjectMeta(&in.ObjectMeta, &out.ObjectMeta, s); err != nil { return err } - if err := conversion.ByteSliceCopy(&in.Data, &out.Data, s); err != nil { + if err := conversion.Convert_Slice_byte_To_Slice_byte(&in.Data, &out.Data, s); err != nil { return err } return nil @@ -5037,7 +5037,7 @@ func autoConvert_v1beta1_ThirdPartyResourceData_To_extensions_ThirdPartyResource if err := Convert_v1_ObjectMeta_To_api_ObjectMeta(&in.ObjectMeta, &out.ObjectMeta, s); err != nil { return err } - if err := conversion.ByteSliceCopy(&in.Data, &out.Data, s); err != nil { + if err := conversion.Convert_Slice_byte_To_Slice_byte(&in.Data, &out.Data, s); err != nil { return err } return nil diff --git a/pkg/conversion/converter.go b/pkg/conversion/converter.go index 19cd4bef9d2f9..29c9fdc86dd7a 100644 --- a/pkg/conversion/converter.go +++ b/pkg/conversion/converter.go @@ -95,7 +95,7 @@ func NewConverter(nameFn NameFunc) *Converter { inputFieldMappingFuncs: make(map[reflect.Type]FieldMappingFunc), inputDefaultFlags: make(map[reflect.Type]FieldMatchingFlags), } - c.RegisterConversionFunc(ByteSliceCopy) + c.RegisterConversionFunc(Convert_Slice_byte_To_Slice_byte) return c } @@ -114,8 +114,8 @@ func (c *Converter) DefaultMeta(t reflect.Type) (FieldMatchingFlags, *Meta) { } } -// ByteSliceCopy prevents recursing into every byte -func ByteSliceCopy(in *[]byte, out *[]byte, s Scope) error { +// Convert_Slice_byte_To_Slice_byte prevents recursing into every byte +func Convert_Slice_byte_To_Slice_byte(in *[]byte, out *[]byte, s Scope) error { *out = make([]byte, len(*in)) copy(*out, *in) return nil diff --git a/pkg/runtime/conversion.go b/pkg/runtime/conversion.go index c13d9d042d255..69cf00fea5d6a 100644 --- a/pkg/runtime/conversion.go +++ b/pkg/runtime/conversion.go @@ -40,13 +40,13 @@ func JSONKeyMapper(key string, sourceTag, destTag reflect.StructTag) (string, st // DefaultStringConversions are helpers for converting []string and string to real values. var DefaultStringConversions = []interface{}{ - convertStringSliceToString, - convertStringSliceToInt, - convertStringSliceToBool, - convertStringSliceToInt64, + Convert_Slice_string_To_string, + Convert_Slice_string_To_int, + Convert_Slice_string_To_bool, + Convert_Slice_string_To_int64, } -func convertStringSliceToString(input *[]string, out *string, s conversion.Scope) error { +func Convert_Slice_string_To_string(input *[]string, out *string, s conversion.Scope) error { if len(*input) == 0 { *out = "" } @@ -54,7 +54,7 @@ func convertStringSliceToString(input *[]string, out *string, s conversion.Scope return nil } -func convertStringSliceToInt(input *[]string, out *int, s conversion.Scope) error { +func Convert_Slice_string_To_int(input *[]string, out *int, s conversion.Scope) error { if len(*input) == 0 { *out = 0 } @@ -67,10 +67,10 @@ func convertStringSliceToInt(input *[]string, out *int, s conversion.Scope) erro return nil } -// converStringSliceToBool will convert a string parameter to boolean. +// Conver_Slice_string_To_bool will convert a string parameter to boolean. // Only the absence of a value, a value of "false", or a value of "0" resolve to false. // Any other value (including empty string) resolves to true. -func convertStringSliceToBool(input *[]string, out *bool, s conversion.Scope) error { +func Convert_Slice_string_To_bool(input *[]string, out *bool, s conversion.Scope) error { if len(*input) == 0 { *out = false return nil @@ -84,7 +84,7 @@ func convertStringSliceToBool(input *[]string, out *bool, s conversion.Scope) er return nil } -func convertStringSliceToInt64(input *[]string, out *int64, s conversion.Scope) error { +func Convert_Slice_string_To_int64(input *[]string, out *int64, s conversion.Scope) error { if len(*input) == 0 { *out = 0 }