mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Cleanup default conversions
This commit is contained in:
parent
d6969d2c55
commit
2df8ad1b1c
@ -53,14 +53,6 @@ func JSONKeyMapper(key string, sourceTag, destTag reflect.StructTag) (string, st
|
|||||||
return key, key
|
return key, key
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultStringConversions are helpers for converting []string and string to real values.
|
|
||||||
var DefaultStringConversions = []interface{}{
|
|
||||||
Convert_Slice_string_To_string,
|
|
||||||
Convert_Slice_string_To_int,
|
|
||||||
Convert_Slice_string_To_bool,
|
|
||||||
Convert_Slice_string_To_int64,
|
|
||||||
}
|
|
||||||
|
|
||||||
func Convert_Slice_string_To_string(in *[]string, out *string, s conversion.Scope) error {
|
func Convert_Slice_string_To_string(in *[]string, out *string, s conversion.Scope) error {
|
||||||
if len(*in) == 0 {
|
if len(*in) == 0 {
|
||||||
*out = ""
|
*out = ""
|
||||||
@ -178,3 +170,27 @@ func Convert_Slice_string_To_Pointer_int64(in *[]string, out **int64, s conversi
|
|||||||
*out = &i
|
*out = &i
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RegisterStringConversions(s *Scheme) error {
|
||||||
|
if err := s.AddConversionFunc((*[]string)(nil), (*string)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return Convert_Slice_string_To_string(a.(*[]string), b.(*string), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*[]string)(nil), (*int)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return Convert_Slice_string_To_int(a.(*[]string), b.(*int), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*[]string)(nil), (*bool)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return Convert_Slice_string_To_bool(a.(*[]string), b.(*bool), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.AddConversionFunc((*[]string)(nil), (*int64)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return Convert_Slice_string_To_int64(a.(*[]string), b.(*int64), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -134,9 +134,16 @@ func Convert_runtime_RawExtension_To_runtime_Object(in *RawExtension, out *Objec
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultEmbeddedConversions() []interface{} {
|
func RegisterEmbeddedConversions(s *Scheme) error {
|
||||||
return []interface{}{
|
if err := s.AddConversionFunc((*Object)(nil), (*RawExtension)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
Convert_runtime_Object_To_runtime_RawExtension,
|
return Convert_runtime_Object_To_runtime_RawExtension(a.(*Object), b.(*RawExtension), scope)
|
||||||
Convert_runtime_RawExtension_To_runtime_Object,
|
}); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
if err := s.AddConversionFunc((*RawExtension)(nil), (*Object)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||||
|
return Convert_runtime_RawExtension_To_runtime_Object(a.(*RawExtension), b.(*Object), scope)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -102,10 +102,10 @@ func NewScheme() *Scheme {
|
|||||||
}
|
}
|
||||||
s.converter = conversion.NewConverter(s.nameFunc)
|
s.converter = conversion.NewConverter(s.nameFunc)
|
||||||
|
|
||||||
utilruntime.Must(s.AddConversionFuncs(DefaultEmbeddedConversions()...))
|
// Enable couple default conversions by default.
|
||||||
|
utilruntime.Must(RegisterEmbeddedConversions(s))
|
||||||
|
utilruntime.Must(RegisterStringConversions(s))
|
||||||
|
|
||||||
// Enable map[string][]string conversions by default
|
|
||||||
utilruntime.Must(s.AddConversionFuncs(DefaultStringConversions...))
|
|
||||||
utilruntime.Must(s.RegisterInputDefaults(&map[string][]string{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields))
|
utilruntime.Must(s.RegisterInputDefaults(&map[string][]string{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields))
|
||||||
utilruntime.Must(s.RegisterInputDefaults(&url.Values{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields))
|
utilruntime.Must(s.RegisterInputDefaults(&url.Values{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields))
|
||||||
return s
|
return s
|
||||||
|
Loading…
Reference in New Issue
Block a user