Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a31d2c44
Commit
a31d2c44
authored
Jun 26, 2018
by
David Eads
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flatten nested lists for flatten in visitor
parent
63c33f38
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
4 deletions
+59
-4
visitor.go
pkg/kubectl/genericclioptions/resource/visitor.go
+20
-4
visitor_test.go
pkg/kubectl/genericclioptions/resource/visitor_test.go
+17
-0
deeply-nested.yaml
test/fixtures/pkg/kubectl/builder/deeply-nested.yaml
+22
-0
No files found.
pkg/kubectl/genericclioptions/resource/visitor.go
View file @
a31d2c44
...
...
@@ -376,12 +376,28 @@ 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
{
return
utilerrors
.
NewAggregate
(
errs
)
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
)
}
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
...
...
pkg/kubectl/genericclioptions/resource/visitor_test.go
View file @
a31d2c44
...
...
@@ -24,6 +24,7 @@ import (
"testing"
"time"
"github.com/davecgh/go-spew/spew"
"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
))
}
}
test/fixtures/pkg/kubectl/builder/deeply-nested.yaml
0 → 100644
View file @
a31d2c44
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
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment