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
1f35cf2e
Commit
1f35cf2e
authored
Sep 30, 2015
by
Janet Kuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix get with List
parent
b1461be2
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 @
1f35cf2e
...
...
@@ -763,8 +763,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 @
1f35cf2e
...
...
@@ -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 @
1f35cf2e
...
...
@@ -94,29 +94,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
},
}
}
...
...
@@ -322,16 +322,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
()
...
...
@@ -349,7 +366,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
)
...
...
@@ -375,10 +395,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"
)
...
...
@@ -411,7 +434,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
)
...
...
@@ -512,7 +538,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