mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #65488 from deads2k/cli-79-really-flatten
Automatic merge from submit-queue (batch tested with PRs 65805, 65811, 65833, 65488, 65857). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. flatten nested lists for flatten in visitor Lists which contain lists should themselves be flattened by a flatten call to the resource builder @kubernetes/sig-cli-maintainers @soltysh @juanvallejo ```release-note NONE ```
This commit is contained in:
commit
1e8ef574c3
@ -376,13 +376,29 @@ func (v FlattenListVisitor) Visit(fn VisitorFunc) error {
|
|||||||
if info.Object == nil {
|
if info.Object == nil {
|
||||||
return fn(info, nil)
|
return fn(info, nil)
|
||||||
}
|
}
|
||||||
items, err := meta.ExtractList(info.Object)
|
if !meta.IsListType(info.Object) {
|
||||||
if err != nil {
|
|
||||||
return fn(info, nil)
|
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)
|
return utilerrors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
|
itemsToProcess = append(itemsToProcess, currItems...)
|
||||||
|
}
|
||||||
|
|
||||||
// If we have a GroupVersionKind on the list, prioritize that when asking for info on the objects contained in the list
|
// 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
|
var preferredGVKs []schema.GroupVersionKind
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -163,3 +164,19 @@ func TestVisitorHttpGet(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFlattenListVisitor(t *testing.T) {
|
||||||
|
b := newDefaultBuilder().
|
||||||
|
FilenameParam(false, &FilenameOptions{Recursive: false, Filenames: []string{"../../../../test/fixtures/pkg/kubectl/builder/deeply-nested.yaml"}}).
|
||||||
|
Flatten()
|
||||||
|
|
||||||
|
test := &testVisitor{}
|
||||||
|
|
||||||
|
err := b.Do().Visit(test.Handle)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(test.Infos) != 6 {
|
||||||
|
t.Fatal(spew.Sdump(test.Infos))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
21
test/fixtures/pkg/kubectl/builder/deeply-nested.yaml
vendored
Normal file
21
test/fixtures/pkg/kubectl/builder/deeply-nested.yaml
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: List
|
||||||
|
items:
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: List
|
||||||
|
items:
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: List
|
||||||
|
items:
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: Pod
|
Loading…
Reference in New Issue
Block a user