mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #23741 from wojtek-t/conversions_with_framework_5
Small improvements in conversion generator
This commit is contained in:
commit
cd2de7d4cd
@ -35,6 +35,7 @@ func main() {
|
|||||||
arguments.InputDirs = []string{
|
arguments.InputDirs = []string{
|
||||||
"k8s.io/kubernetes/pkg/api/v1",
|
"k8s.io/kubernetes/pkg/api/v1",
|
||||||
"k8s.io/kubernetes/pkg/api",
|
"k8s.io/kubernetes/pkg/api",
|
||||||
|
"k8s.io/kubernetes/pkg/conversion",
|
||||||
"k8s.io/kubernetes/pkg/runtime",
|
"k8s.io/kubernetes/pkg/runtime",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,20 +41,20 @@ func init() {
|
|||||||
Convert_unversioned_ListMeta_To_unversioned_ListMeta,
|
Convert_unversioned_ListMeta_To_unversioned_ListMeta,
|
||||||
Convert_intstr_IntOrString_To_intstr_IntOrString,
|
Convert_intstr_IntOrString_To_intstr_IntOrString,
|
||||||
Convert_unversioned_Time_To_unversioned_Time,
|
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_labels_Selector,
|
||||||
Convert_string_To_fields_Selector,
|
Convert_string_To_fields_Selector,
|
||||||
Convert_bool_ref_To_bool,
|
Convert_Pointer_bool_To_bool,
|
||||||
Convert_bool_To_bool_ref,
|
Convert_bool_To_Pointer_bool,
|
||||||
Convert_string_ref_To_string,
|
Convert_Pointer_string_To_string,
|
||||||
Convert_string_To_string_ref,
|
Convert_string_To_Pointer_string,
|
||||||
Convert_labels_Selector_To_string,
|
Convert_labels_Selector_To_string,
|
||||||
Convert_fields_Selector_To_string,
|
Convert_fields_Selector_To_string,
|
||||||
Convert_resource_Quantity_To_resource_Quantity,
|
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 {
|
if *in == nil {
|
||||||
*out = ""
|
*out = ""
|
||||||
return nil
|
return nil
|
||||||
@ -63,7 +63,7 @@ func Convert_string_ref_To_string(in **string, out *string, s conversion.Scope)
|
|||||||
return nil
|
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 {
|
if in == nil {
|
||||||
stringVar := ""
|
stringVar := ""
|
||||||
*out = &stringVar
|
*out = &stringVar
|
||||||
@ -73,7 +73,7 @@ func Convert_string_To_string_ref(in *string, out **string, s conversion.Scope)
|
|||||||
return nil
|
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 {
|
if *in == nil {
|
||||||
*out = false
|
*out = false
|
||||||
return nil
|
return nil
|
||||||
@ -82,7 +82,7 @@ func Convert_bool_ref_To_bool(in **bool, out *bool, s conversion.Scope) error {
|
|||||||
return nil
|
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 {
|
if in == nil {
|
||||||
boolVar := false
|
boolVar := false
|
||||||
*out = &boolVar
|
*out = &boolVar
|
||||||
@ -118,8 +118,8 @@ func Convert_unversioned_Time_To_unversioned_Time(in *unversioned.Time, out *unv
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert_string_slice_To_unversioned_Time allows converting a URL query parameter value
|
// Convert_Slice_string_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 {
|
func Convert_Slice_string_To_unversioned_Time(input *[]string, out *unversioned.Time, s conversion.Scope) error {
|
||||||
str := ""
|
str := ""
|
||||||
if len(*input) > 0 {
|
if len(*input) > 0 {
|
||||||
str = (*input)[0]
|
str = (*input)[0]
|
||||||
|
@ -5805,12 +5805,8 @@ func autoConvert_v1_RangeAllocation_To_api_RangeAllocation(in *RangeAllocation,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Range = in.Range
|
out.Range = in.Range
|
||||||
if in.Data != nil {
|
if err := conversion.Convert_Slice_byte_To_Slice_byte(&in.Data, &out.Data, s); err != nil {
|
||||||
in, out := &in.Data, &out.Data
|
return err
|
||||||
*out = make([]byte, len(*in))
|
|
||||||
copy(*out, *in)
|
|
||||||
} else {
|
|
||||||
out.Data = nil
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -5830,12 +5826,8 @@ func autoConvert_api_RangeAllocation_To_v1_RangeAllocation(in *api.RangeAllocati
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Range = in.Range
|
out.Range = in.Range
|
||||||
if in.Data != nil {
|
if err := conversion.Convert_Slice_byte_To_Slice_byte(&in.Data, &out.Data, s); err != nil {
|
||||||
in, out := &in.Data, &out.Data
|
return err
|
||||||
*out = make([]byte, len(*in))
|
|
||||||
copy(*out, *in)
|
|
||||||
} else {
|
|
||||||
out.Data = nil
|
|
||||||
}
|
}
|
||||||
return nil
|
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))
|
*out = make(map[string][]byte, len(*in))
|
||||||
for key, val := range *in {
|
for key, val := range *in {
|
||||||
newVal := new([]byte)
|
newVal := new([]byte)
|
||||||
// TODO: Inefficient conversion - can we improve it?
|
if err := conversion.Convert_Slice_byte_To_Slice_byte(&val, newVal, s); err != nil {
|
||||||
if err := s.Convert(&val, newVal, 0); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
(*out)[key] = *newVal
|
(*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))
|
*out = make(map[string][]byte, len(*in))
|
||||||
for key, val := range *in {
|
for key, val := range *in {
|
||||||
newVal := new([]byte)
|
newVal := new([]byte)
|
||||||
// TODO: Inefficient conversion - can we improve it?
|
if err := conversion.Convert_Slice_byte_To_Slice_byte(&val, newVal, s); err != nil {
|
||||||
if err := s.Convert(&val, newVal, 0); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
(*out)[key] = *newVal
|
(*out)[key] = *newVal
|
||||||
|
@ -83,7 +83,7 @@ func autoConvert_componentconfig_KubeSchedulerConfiguration_To_v1alpha1_KubeSche
|
|||||||
out.Address = in.Address
|
out.Address = in.Address
|
||||||
out.AlgorithmProvider = in.AlgorithmProvider
|
out.AlgorithmProvider = in.AlgorithmProvider
|
||||||
out.PolicyConfigFile = in.PolicyConfigFile
|
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
|
return err
|
||||||
}
|
}
|
||||||
out.KubeAPIQPS = in.KubeAPIQPS
|
out.KubeAPIQPS = in.KubeAPIQPS
|
||||||
@ -103,7 +103,7 @@ func autoConvert_componentconfig_LeaderElectionConfiguration_To_v1alpha1_LeaderE
|
|||||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||||
defaulting.(func(*componentconfig.LeaderElectionConfiguration))(in)
|
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
|
return err
|
||||||
}
|
}
|
||||||
if err := s.Convert(&in.LeaseDuration, &out.LeaseDuration, 0); err != nil {
|
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.Address = in.Address
|
||||||
out.AlgorithmProvider = in.AlgorithmProvider
|
out.AlgorithmProvider = in.AlgorithmProvider
|
||||||
out.PolicyConfigFile = in.PolicyConfigFile
|
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
|
return err
|
||||||
}
|
}
|
||||||
out.KubeAPIQPS = in.KubeAPIQPS
|
out.KubeAPIQPS = in.KubeAPIQPS
|
||||||
@ -199,7 +199,7 @@ func autoConvert_v1alpha1_LeaderElectionConfiguration_To_componentconfig_LeaderE
|
|||||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||||
defaulting.(func(*LeaderElectionConfiguration))(in)
|
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
|
return err
|
||||||
}
|
}
|
||||||
if err := s.Convert(&in.LeaseDuration, &out.LeaseDuration, 0); err != nil {
|
if err := s.Convert(&in.LeaseDuration, &out.LeaseDuration, 0); err != nil {
|
||||||
|
@ -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 {
|
if err := Convert_api_ObjectMeta_To_v1_ObjectMeta(&in.ObjectMeta, &out.ObjectMeta, s); err != nil {
|
||||||
return err
|
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 err
|
||||||
}
|
}
|
||||||
return nil
|
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 {
|
if err := Convert_v1_ObjectMeta_To_api_ObjectMeta(&in.ObjectMeta, &out.ObjectMeta, s); err != nil {
|
||||||
return err
|
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 err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -95,7 +95,7 @@ func NewConverter(nameFn NameFunc) *Converter {
|
|||||||
inputFieldMappingFuncs: make(map[reflect.Type]FieldMappingFunc),
|
inputFieldMappingFuncs: make(map[reflect.Type]FieldMappingFunc),
|
||||||
inputDefaultFlags: make(map[reflect.Type]FieldMatchingFlags),
|
inputDefaultFlags: make(map[reflect.Type]FieldMatchingFlags),
|
||||||
}
|
}
|
||||||
c.RegisterConversionFunc(ByteSliceCopy)
|
c.RegisterConversionFunc(Convert_Slice_byte_To_Slice_byte)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +114,8 @@ func (c *Converter) DefaultMeta(t reflect.Type) (FieldMatchingFlags, *Meta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByteSliceCopy prevents recursing into every byte
|
// Convert_Slice_byte_To_Slice_byte prevents recursing into every byte
|
||||||
func ByteSliceCopy(in *[]byte, out *[]byte, s Scope) error {
|
func Convert_Slice_byte_To_Slice_byte(in *[]byte, out *[]byte, s Scope) error {
|
||||||
*out = make([]byte, len(*in))
|
*out = make([]byte, len(*in))
|
||||||
copy(*out, *in)
|
copy(*out, *in)
|
||||||
return nil
|
return nil
|
||||||
|
@ -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.
|
// DefaultStringConversions are helpers for converting []string and string to real values.
|
||||||
var DefaultStringConversions = []interface{}{
|
var DefaultStringConversions = []interface{}{
|
||||||
convertStringSliceToString,
|
Convert_Slice_string_To_string,
|
||||||
convertStringSliceToInt,
|
Convert_Slice_string_To_int,
|
||||||
convertStringSliceToBool,
|
Convert_Slice_string_To_bool,
|
||||||
convertStringSliceToInt64,
|
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 {
|
if len(*input) == 0 {
|
||||||
*out = ""
|
*out = ""
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ func convertStringSliceToString(input *[]string, out *string, s conversion.Scope
|
|||||||
return nil
|
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 {
|
if len(*input) == 0 {
|
||||||
*out = 0
|
*out = 0
|
||||||
}
|
}
|
||||||
@ -67,10 +67,10 @@ func convertStringSliceToInt(input *[]string, out *int, s conversion.Scope) erro
|
|||||||
return nil
|
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.
|
// 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.
|
// 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 {
|
if len(*input) == 0 {
|
||||||
*out = false
|
*out = false
|
||||||
return nil
|
return nil
|
||||||
@ -84,7 +84,7 @@ func convertStringSliceToBool(input *[]string, out *bool, s conversion.Scope) er
|
|||||||
return nil
|
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 {
|
if len(*input) == 0 {
|
||||||
*out = 0
|
*out = 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user