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
a1bba622
Commit
a1bba622
authored
May 20, 2018
by
Cao Shufeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix kubectl get --show-kind
parent
2a989c60
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
11 deletions
+72
-11
get.go
pkg/kubectl/cmd/get/get.go
+4
-3
get_flags.go
pkg/kubectl/cmd/get/get_flags.go
+7
-2
get_test.go
pkg/kubectl/cmd/get/get_test.go
+54
-0
humanreadable_flags.go
pkg/kubectl/cmd/get/humanreadable_flags.go
+7
-6
No files found.
pkg/kubectl/cmd/get/get.go
View file @
a1bba622
...
@@ -219,6 +219,9 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
...
@@ -219,6 +219,9 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
o
.
IncludeUninitialized
=
cmdutil
.
ShouldIncludeUninitialized
(
cmd
,
false
)
o
.
IncludeUninitialized
=
cmdutil
.
ShouldIncludeUninitialized
(
cmd
,
false
)
if
resource
.
MultipleTypesRequested
(
args
)
{
o
.
PrintFlags
.
EnsureWithKind
()
}
o
.
ToPrinter
=
func
(
mapping
*
meta
.
RESTMapping
,
withNamespace
bool
)
(
printers
.
ResourcePrinterFunc
,
error
)
{
o
.
ToPrinter
=
func
(
mapping
*
meta
.
RESTMapping
,
withNamespace
bool
)
(
printers
.
ResourcePrinterFunc
,
error
)
{
// make a new copy of current flags / opts before mutating
// make a new copy of current flags / opts before mutating
printFlags
:=
o
.
PrintFlags
.
Copy
()
printFlags
:=
o
.
PrintFlags
.
Copy
()
...
@@ -229,9 +232,7 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
...
@@ -229,9 +232,7 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
printFlags
.
UseOpenAPIColumns
(
apiSchema
,
mapping
)
printFlags
.
UseOpenAPIColumns
(
apiSchema
,
mapping
)
}
}
}
}
if
resource
.
MultipleTypesRequested
(
args
)
{
printFlags
.
SetKind
(
mapping
.
GroupVersionKind
.
GroupKind
())
printFlags
.
EnsureWithKind
(
mapping
.
GroupVersionKind
.
GroupKind
())
}
}
}
if
withNamespace
{
if
withNamespace
{
printFlags
.
EnsureWithNamespace
()
printFlags
.
EnsureWithNamespace
()
...
...
pkg/kubectl/cmd/get/get_flags.go
View file @
a1bba622
...
@@ -41,6 +41,11 @@ type PrintFlags struct {
...
@@ -41,6 +41,11 @@ type PrintFlags struct {
OutputFormat
*
string
OutputFormat
*
string
}
}
// SetKind sets the Kind option of humanreadable flags
func
(
f
*
PrintFlags
)
SetKind
(
kind
schema
.
GroupKind
)
{
f
.
HumanReadableFlags
.
SetKind
(
kind
)
}
// EnsureWithNamespace ensures that humanreadable flags return
// EnsureWithNamespace ensures that humanreadable flags return
// a printer capable of printing with a "namespace" column.
// a printer capable of printing with a "namespace" column.
func
(
f
*
PrintFlags
)
EnsureWithNamespace
()
error
{
func
(
f
*
PrintFlags
)
EnsureWithNamespace
()
error
{
...
@@ -49,8 +54,8 @@ func (f *PrintFlags) EnsureWithNamespace() error {
...
@@ -49,8 +54,8 @@ func (f *PrintFlags) EnsureWithNamespace() error {
// EnsureWithKind ensures that humanreadable flags return
// EnsureWithKind ensures that humanreadable flags return
// a printer capable of including resource kinds.
// a printer capable of including resource kinds.
func
(
f
*
PrintFlags
)
EnsureWithKind
(
kind
schema
.
GroupKind
)
error
{
func
(
f
*
PrintFlags
)
EnsureWithKind
()
error
{
return
f
.
HumanReadableFlags
.
EnsureWithKind
(
kind
)
return
f
.
HumanReadableFlags
.
EnsureWithKind
()
}
}
// Copy returns a copy of PrintFlags for mutation
// Copy returns a copy of PrintFlags for mutation
...
...
pkg/kubectl/cmd/get/get_test.go
View file @
a1bba622
...
@@ -329,6 +329,60 @@ foo 0/0 0 <unknown>
...
@@ -329,6 +329,60 @@ foo 0/0 0 <unknown>
}
}
}
}
func
TestGetObjectsShowKind
(
t
*
testing
.
T
)
{
pods
,
_
,
_
:=
testData
()
tf
:=
cmdtesting
.
NewTestFactory
()
defer
tf
.
Cleanup
()
codec
:=
legacyscheme
.
Codecs
.
LegacyCodec
(
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
)
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
NegotiatedSerializer
:
unstructuredSerializer
,
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
}
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"show-kind"
,
"true"
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
,
"foo"
})
expected
:=
`NAME READY STATUS RESTARTS AGE
pod/foo 0/0 0 <unknown>
`
if
e
,
a
:=
expected
,
buf
.
String
();
e
!=
a
{
t
.
Errorf
(
"expected %v, got %v"
,
e
,
a
)
}
}
func
TestGetObjectsShowLabels
(
t
*
testing
.
T
)
{
pods
,
_
,
_
:=
testData
()
tf
:=
cmdtesting
.
NewTestFactory
()
defer
tf
.
Cleanup
()
codec
:=
legacyscheme
.
Codecs
.
LegacyCodec
(
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
)
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
NegotiatedSerializer
:
unstructuredSerializer
,
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
}
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"show-labels"
,
"true"
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
,
"foo"
})
expected
:=
`NAME READY STATUS RESTARTS AGE LABELS
foo 0/0 0 <unknown> <none>
`
if
e
,
a
:=
expected
,
buf
.
String
();
e
!=
a
{
t
.
Errorf
(
"expected %v, got %v"
,
e
,
a
)
}
}
func
TestGetObjectIgnoreNotFound
(
t
*
testing
.
T
)
{
func
TestGetObjectIgnoreNotFound
(
t
*
testing
.
T
)
{
initTestErrorHandler
(
t
)
initTestErrorHandler
(
t
)
...
...
pkg/kubectl/cmd/get/humanreadable_flags.go
View file @
a1bba622
...
@@ -43,13 +43,14 @@ type HumanPrintFlags struct {
...
@@ -43,13 +43,14 @@ type HumanPrintFlags struct {
WithNamespace
bool
WithNamespace
bool
}
}
// EnsureWithKind sets the provided GroupKind humanreadable value.
// SetKind sets the Kind option
// If the kind received is non-empty, the "showKind" humanreadable
func
(
f
*
HumanPrintFlags
)
SetKind
(
kind
schema
.
GroupKind
)
{
// printer option is set to true.
func
(
f
*
HumanPrintFlags
)
EnsureWithKind
(
kind
schema
.
GroupKind
)
error
{
showKind
:=
!
kind
.
Empty
()
f
.
Kind
=
kind
f
.
Kind
=
kind
}
// EnsureWithKind sets the "Showkind" humanreadable option to true.
func
(
f
*
HumanPrintFlags
)
EnsureWithKind
()
error
{
showKind
:=
true
f
.
ShowKind
=
&
showKind
f
.
ShowKind
=
&
showKind
return
nil
return
nil
}
}
...
...
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