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
091a9dfc
Commit
091a9dfc
authored
Aug 24, 2017
by
jianhuiz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
outputs <none> for colums not found
parent
e33dd983
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
customcolumn.go
pkg/printers/customcolumn.go
+3
-3
customcolumn_test.go
pkg/printers/customcolumn_test.go
+20
-0
No files found.
pkg/printers/customcolumn.go
View file @
091a9dfc
...
...
@@ -176,7 +176,7 @@ func (s *CustomColumnsPrinter) PrintObj(obj runtime.Object, out io.Writer) error
}
parsers
:=
make
([]
*
jsonpath
.
JSONPath
,
len
(
s
.
Columns
))
for
ix
:=
range
s
.
Columns
{
parsers
[
ix
]
=
jsonpath
.
New
(
fmt
.
Sprintf
(
"column%d"
,
ix
))
parsers
[
ix
]
=
jsonpath
.
New
(
fmt
.
Sprintf
(
"column%d"
,
ix
))
.
AllowMissingKeys
(
true
)
if
err
:=
parsers
[
ix
]
.
Parse
(
s
.
Columns
[
ix
]
.
FieldSpec
);
err
!=
nil
{
return
err
}
...
...
@@ -226,10 +226,10 @@ func (s *CustomColumnsPrinter) printOneObject(obj runtime.Object, parsers []*jso
if
err
!=
nil
{
return
err
}
valueStrings
:=
[]
string
{}
if
len
(
values
)
==
0
||
len
(
values
[
0
])
==
0
{
fmt
.
Fprintf
(
out
,
"<none>
\t
"
)
valueStrings
=
append
(
valueStrings
,
"<none>
"
)
}
valueStrings
:=
[]
string
{}
for
arrIx
:=
range
values
{
for
valIx
:=
range
values
[
arrIx
]
{
valueStrings
=
append
(
valueStrings
,
fmt
.
Sprintf
(
"%v"
,
values
[
arrIx
][
valIx
]
.
Interface
()))
...
...
pkg/printers/customcolumn_test.go
View file @
091a9dfc
...
...
@@ -286,6 +286,26 @@ bar
foo baz
`
,
},
{
columns
:
[]
printers
.
Column
{
{
Header
:
"NAME"
,
FieldSpec
:
"{.metadata.name}"
,
},
{
Header
:
"API_VERSION"
,
FieldSpec
:
"{.apiVersion}"
,
},
{
Header
:
"NOT_FOUND"
,
FieldSpec
:
"{.notFound}"
,
},
},
obj
:
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
},
TypeMeta
:
metav1
.
TypeMeta
{
APIVersion
:
"baz"
}},
expectedOutput
:
`NAME API_VERSION NOT_FOUND
foo baz <none>
`
,
},
}
for
_
,
test
:=
range
tests
{
...
...
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