UPSTREAM: 65488: flatten nested lists for flatten in visitor
@@ -376,13 +376,29 @@ func (v FlattenListVisitor) Visit(fn VisitorFunc) error {
if info.Object == nil {
return fn(info, nil)
}
- items, err := meta.ExtractList(info.Object)
- if err != nil {
+ if !meta.IsListType(info.Object) {
return fn(info, nil)
}
- if errs := runtime.DecodeList(items, v.mapper.decoder); len(errs) > 0 {
+
+ items := []runtime.Object{}
+ itemsToProcess := []runtime.Object{info.Object}
+
+ for i := 0; i < len(itemsToProcess); i++ {
+ currObj := itemsToProcess[i]
+ if !meta.IsListType(currObj) {
+ items = append(items, currObj)
+ continue
+ }
+
+ currItems, err := meta.ExtractList(currObj)
+ if err != nil {
+ return err
+ }
+ if errs := runtime.DecodeList(currItems, v.mapper.decoder); len(errs) > 0 {
return utilerrors.NewAggregate(errs)
}
+ items = append(items, currItems...)
+ }
// If we have a GroupVersionKind on the list, prioritize that when asking for info on the objects contained in the list
var preferredGVKs []schema.GroupVersionKind
