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
0fb7c80e
Commit
0fb7c80e
authored
Oct 09, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14888 from JanetKuo/kubectl-get-list
Auto commit by PR queue bot
parents
1f764fcd
1f35cf2e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
17 deletions
+45
-17
test-cmd.sh
hack/test-cmd.sh
+1
-2
get.go
pkg/kubectl/cmd/get.go
+1
-1
get_test.go
pkg/kubectl/cmd/get_test.go
+43
-14
No files found.
hack/test-cmd.sh
View file @
0fb7c80e
...
...
@@ -775,8 +775,7 @@ __EOF__
kube::test::get_object_assert rc
"{{range.items}}{{
$id_field
}}:{{end}}"
'mock:'
# Command
# kubectl create -f $file "${kube_flags[@]}" # test fails here now
# TODO: test get when PR "Fix get with List #14888" is merged
# kubectl get -f $file "${kube_flags[@]}"
kubectl get
-f
$file
"
${
kube_flags
[@]
}
"
kubectl describe
-f
$file
"
${
kube_flags
[@]
}
"
# Command
# TODO: remove --validate=false when PR "Add validate support for list kind #14726" is merged
...
...
pkg/kubectl/cmd/get.go
View file @
0fb7c80e
...
...
@@ -220,7 +220,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
}
// use the default printer for each object
return
b
.
Do
()
.
Visit
(
func
(
r
*
resource
.
Info
,
err
error
)
error
{
return
b
.
Flatten
()
.
Do
()
.
Visit
(
func
(
r
*
resource
.
Info
,
err
error
)
error
{
if
err
!=
nil
{
return
err
}
...
...
pkg/kubectl/cmd/get_test.go
View file @
0fb7c80e
...
...
@@ -86,29 +86,29 @@ func testData() (*api.PodList, *api.ServiceList, *api.ReplicationControllerList)
}
func
testComponentStatusData
()
*
api
.
ComponentStatusList
{
good
:=
&
api
.
ComponentStatus
{
good
:=
api
.
ComponentStatus
{
Conditions
:
[]
api
.
ComponentCondition
{
{
Type
:
api
.
ComponentHealthy
,
Status
:
api
.
ConditionTrue
,
Message
:
"ok"
,
Error
:
"nil"
},
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"servergood"
,
Namespace
:
"test"
},
}
good
.
Name
=
"servergood"
bad
:=
&
api
.
ComponentStatus
{
bad
:=
api
.
ComponentStatus
{
Conditions
:
[]
api
.
ComponentCondition
{
{
Type
:
api
.
ComponentHealthy
,
Status
:
api
.
ConditionFalse
,
Message
:
""
,
Error
:
"bad status: 500"
},
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"serverbad"
,
Namespace
:
"test"
},
}
bad
.
Name
=
"serverbad"
unknown
:=
&
api
.
ComponentStatus
{
unknown
:=
api
.
ComponentStatus
{
Conditions
:
[]
api
.
ComponentCondition
{
{
Type
:
api
.
ComponentHealthy
,
Status
:
api
.
ConditionUnknown
,
Message
:
""
,
Error
:
"fizzbuzz error"
},
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"serverunknown"
,
Namespace
:
"test"
},
}
unknown
.
Name
=
"serverunknown"
return
&
api
.
ComponentStatusList
{
Items
:
[]
api
.
ComponentStatus
{
*
good
,
*
bad
,
*
unknown
},
Items
:
[]
api
.
ComponentStatus
{
good
,
bad
,
unknown
},
}
}
...
...
@@ -314,16 +314,33 @@ func TestGetListObjects(t *testing.T) {
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
expected
:=
[]
runtime
.
Object
{
pods
}
expected
,
err
:=
extractResourceList
([]
runtime
.
Object
{
pods
})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
actual
:=
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
if
!
reflect
.
DeepEqual
(
expected
,
actual
)
{
t
.
Errorf
(
"unexpected object:
%#v
%#v"
,
expected
,
actual
)
t
.
Errorf
(
"unexpected object:
expected %#v, got
%#v"
,
expected
,
actual
)
}
if
len
(
buf
.
String
())
==
0
{
t
.
Errorf
(
"unexpected empty output"
)
}
}
func
extractResourceList
(
objs
[]
runtime
.
Object
)
([]
runtime
.
Object
,
error
)
{
finalObjs
:=
[]
runtime
.
Object
{}
for
_
,
obj
:=
range
objs
{
items
,
err
:=
runtime
.
ExtractList
(
obj
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
item
:=
range
items
{
finalObjs
=
append
(
finalObjs
,
item
)
}
}
return
finalObjs
,
nil
}
func
TestGetAllListObjects
(
t
*
testing
.
T
)
{
pods
,
_
,
_
:=
testData
()
...
...
@@ -341,7 +358,10 @@ func TestGetAllListObjects(t *testing.T) {
cmd
.
Flags
()
.
Set
(
"show-all"
,
"true"
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
expected
:=
[]
runtime
.
Object
{
pods
}
expected
,
err
:=
extractResourceList
([]
runtime
.
Object
{
pods
})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
actual
:=
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
if
!
reflect
.
DeepEqual
(
expected
,
actual
)
{
t
.
Errorf
(
"unexpected object: %#v %#v"
,
expected
,
actual
)
...
...
@@ -367,10 +387,13 @@ func TestGetListComponentStatus(t *testing.T) {
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"componentstatuses"
})
expected
:=
[]
runtime
.
Object
{
statuses
}
expected
,
err
:=
extractResourceList
([]
runtime
.
Object
{
statuses
})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
actual
:=
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
if
!
reflect
.
DeepEqual
(
expected
,
actual
)
{
t
.
Errorf
(
"unexpected object:
%#v
%#v"
,
expected
,
actual
)
t
.
Errorf
(
"unexpected object:
expected %#v, got
%#v"
,
expected
,
actual
)
}
if
len
(
buf
.
String
())
==
0
{
t
.
Errorf
(
"unexpected empty output"
)
...
...
@@ -403,7 +426,10 @@ func TestGetMultipleTypeObjects(t *testing.T) {
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods,services"
})
expected
:=
[]
runtime
.
Object
{
pods
,
svc
}
expected
,
err
:=
extractResourceList
([]
runtime
.
Object
{
pods
,
svc
})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
actual
:=
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
if
!
reflect
.
DeepEqual
(
expected
,
actual
)
{
t
.
Errorf
(
"unexpected object: %#v"
,
actual
)
...
...
@@ -504,7 +530,10 @@ func TestGetMultipleTypeObjectsWithSelector(t *testing.T) {
cmd
.
Flags
()
.
Set
(
"selector"
,
"a=b"
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods,services"
})
expected
:=
[]
runtime
.
Object
{
pods
,
svc
}
expected
,
err
:=
extractResourceList
([]
runtime
.
Object
{
pods
,
svc
})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
actual
:=
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
if
!
reflect
.
DeepEqual
(
expected
,
actual
)
{
t
.
Errorf
(
"unexpected object: %#v"
,
actual
)
...
...
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