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
492c5d68
Commit
492c5d68
authored
Mar 07, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21694 from aveshagarwal/master-sort-by-versioned
Auto commit by PR queue bot
parents
ec9c67d6
be06003e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
2 deletions
+72
-2
get.go
pkg/kubectl/cmd/get.go
+22
-2
get_test.go
pkg/kubectl/cmd/get_test.go
+50
-0
No files found.
pkg/kubectl/cmd/get.go
View file @
492c5d68
...
...
@@ -248,6 +248,23 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
sorting
,
err
:=
cmd
.
Flags
()
.
GetString
(
"sort-by"
)
var
sorter
*
kubectl
.
RuntimeSort
if
err
==
nil
&&
len
(
sorting
)
>
0
&&
len
(
objs
)
>
1
{
clientConfig
,
err
:=
f
.
ClientConfig
()
if
err
!=
nil
{
return
err
}
version
,
err
:=
cmdutil
.
OutputVersion
(
cmd
,
clientConfig
.
GroupVersion
)
if
err
!=
nil
{
return
err
}
for
ix
:=
range
infos
{
objs
[
ix
],
err
=
infos
[
ix
]
.
Mapping
.
ConvertToVersion
(
infos
[
ix
]
.
Object
,
version
.
String
())
if
err
!=
nil
{
return
err
}
}
// TODO: questionable
if
sorter
,
err
=
kubectl
.
SortObjects
(
f
.
Decoder
(
true
),
objs
,
sorting
);
err
!=
nil
{
return
err
...
...
@@ -262,10 +279,13 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
for
ix
:=
range
objs
{
var
mapping
*
meta
.
RESTMapping
var
original
runtime
.
Object
if
sorter
!=
nil
{
mapping
=
infos
[
sorter
.
OriginalPosition
(
ix
)]
.
Mapping
original
=
infos
[
sorter
.
OriginalPosition
(
ix
)]
.
Object
}
else
{
mapping
=
infos
[
ix
]
.
Mapping
original
=
infos
[
ix
]
.
Object
}
if
printer
==
nil
||
lastMapping
==
nil
||
mapping
==
nil
||
mapping
.
Resource
!=
lastMapping
.
Resource
{
printer
,
err
=
f
.
PrinterForMapping
(
cmd
,
mapping
,
allNamespaces
)
...
...
@@ -275,12 +295,12 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
lastMapping
=
mapping
}
if
_
,
found
:=
printer
.
(
*
kubectl
.
HumanReadablePrinter
);
found
{
if
err
:=
printer
.
PrintObj
(
o
bjs
[
ix
]
,
w
);
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
o
riginal
,
w
);
err
!=
nil
{
return
err
}
continue
}
if
err
:=
printer
.
PrintObj
(
o
bjs
[
ix
]
,
w
);
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
o
riginal
,
w
);
err
!=
nil
{
return
err
}
}
...
...
pkg/kubectl/cmd/get_test.go
View file @
492c5d68
...
...
@@ -273,6 +273,56 @@ func TestGetObjects(t *testing.T) {
}
}
func
TestGetSortedObjects
(
t
*
testing
.
T
)
{
pods
:=
&
api
.
PodList
{
ListMeta
:
unversioned
.
ListMeta
{
ResourceVersion
:
"15"
,
},
Items
:
[]
api
.
Pod
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"c"
,
Namespace
:
"test"
,
ResourceVersion
:
"10"
},
Spec
:
apitesting
.
DeepEqualSafePodSpec
(),
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"b"
,
Namespace
:
"test"
,
ResourceVersion
:
"11"
},
Spec
:
apitesting
.
DeepEqualSafePodSpec
(),
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"a"
,
Namespace
:
"test"
,
ResourceVersion
:
"9"
},
Spec
:
apitesting
.
DeepEqualSafePodSpec
(),
},
},
}
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
tf
.
Client
=
&
fake
.
RESTClient
{
Codec
:
codec
,
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
pods
)},
}
tf
.
Namespace
=
"test"
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
"v1"
}}}
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdGet
(
f
,
buf
)
cmd
.
SetOutput
(
buf
)
// sorting with metedata.name
cmd
.
Flags
()
.
Set
(
"sort-by"
,
".metadata.name"
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
// expect sorted: a,b,c
expected
:=
[]
runtime
.
Object
{
&
pods
.
Items
[
2
],
&
pods
.
Items
[
1
],
&
pods
.
Items
[
0
]}
actual
:=
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
if
!
reflect
.
DeepEqual
(
expected
,
actual
)
{
t
.
Errorf
(
"unexpected object: %#v"
,
actual
)
}
if
len
(
buf
.
String
())
==
0
{
t
.
Errorf
(
"unexpected empty output"
)
}
}
func
TestGetObjectsIdentifiedByFile
(
t
*
testing
.
T
)
{
pods
,
_
,
_
:=
testData
()
...
...
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