mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #106797 from kidlj/fix_mapToUnstructured_todo
resolve TODO in mapToUnstructured and sliceToUnstructured
This commit is contained in:
commit
9968b0eff0
@ -705,21 +705,10 @@ func mapToUnstructured(sv, dv reflect.Value) error {
|
|||||||
}
|
}
|
||||||
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
|
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
|
||||||
if st.Key().Kind() == reflect.String {
|
if st.Key().Kind() == reflect.String {
|
||||||
switch st.Elem().Kind() {
|
dv.Set(reflect.MakeMap(mapStringInterfaceType))
|
||||||
// TODO It should be possible to reuse the slice for primitive types.
|
dv = dv.Elem()
|
||||||
// However, it is panicing in the following form.
|
dt = dv.Type()
|
||||||
// case reflect.String, reflect.Bool,
|
|
||||||
// reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
// reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
|
||||||
// sv.Set(sv)
|
|
||||||
// return nil
|
|
||||||
default:
|
|
||||||
// We need to do a proper conversion.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dv.Set(reflect.MakeMap(mapStringInterfaceType))
|
|
||||||
dv = dv.Elem()
|
|
||||||
dt = dv.Type()
|
|
||||||
}
|
}
|
||||||
if dt.Kind() != reflect.Map {
|
if dt.Kind() != reflect.Map {
|
||||||
return fmt.Errorf("cannot convert map to: %v", dt.Kind())
|
return fmt.Errorf("cannot convert map to: %v", dt.Kind())
|
||||||
@ -763,20 +752,9 @@ func sliceToUnstructured(sv, dv reflect.Value) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
|
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
|
||||||
switch st.Elem().Kind() {
|
dv.Set(reflect.MakeSlice(reflect.SliceOf(dt), sv.Len(), sv.Cap()))
|
||||||
// TODO It should be possible to reuse the slice for primitive types.
|
dv = dv.Elem()
|
||||||
// However, it is panicing in the following form.
|
dt = dv.Type()
|
||||||
// case reflect.String, reflect.Bool,
|
|
||||||
// reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
// reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
|
||||||
// sv.Set(sv)
|
|
||||||
// return nil
|
|
||||||
default:
|
|
||||||
// We need to do a proper conversion.
|
|
||||||
dv.Set(reflect.MakeSlice(reflect.SliceOf(dt), sv.Len(), sv.Cap()))
|
|
||||||
dv = dv.Elem()
|
|
||||||
dt = dv.Type()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if dt.Kind() != reflect.Slice {
|
if dt.Kind() != reflect.Slice {
|
||||||
return fmt.Errorf("cannot convert slice to: %v", dt.Kind())
|
return fmt.Errorf("cannot convert slice to: %v", dt.Kind())
|
||||||
|
Loading…
Reference in New Issue
Block a user