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
9788101e
Commit
9788101e
authored
Mar 11, 2016
by
AdoHe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update wide option output
parent
6773c2b6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
121 deletions
+109
-121
cmd_test.go
pkg/kubectl/cmd/cmd_test.go
+55
-3
resource_printer.go
pkg/kubectl/resource_printer.go
+54
-118
No files found.
pkg/kubectl/cmd/cmd_test.go
View file @
9788101e
...
@@ -389,7 +389,7 @@ func ExamplePrintReplicationControllerWithNamespace() {
...
@@ -389,7 +389,7 @@ func ExamplePrintReplicationControllerWithNamespace() {
// beep foo 1 1 10y
// beep foo 1 1 10y
}
}
func
ExamplePrintReplicationControllerWithWide
()
{
func
ExamplePrint
MultiContainers
ReplicationControllerWithWide
()
{
f
,
tf
,
codec
:=
NewAPIFactory
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
false
,
true
,
false
,
false
,
false
,
[]
string
{})
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
false
,
true
,
false
,
false
,
false
,
[]
string
{})
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Client
=
&
fake
.
RESTClient
{
...
@@ -416,6 +416,58 @@ func ExamplePrintReplicationControllerWithWide() {
...
@@ -416,6 +416,58 @@ func ExamplePrintReplicationControllerWithWide() {
Name
:
"foo"
,
Name
:
"foo"
,
Image
:
"someimage"
,
Image
:
"someimage"
,
},
},
{
Name
:
"foo2"
,
Image
:
"someimage2"
,
},
},
},
},
},
Status
:
api
.
ReplicationControllerStatus
{
Replicas
:
1
,
},
}
err
:=
f
.
PrintObject
(
cmd
,
ctrl
,
os
.
Stdout
)
if
err
!=
nil
{
fmt
.
Printf
(
"Unexpected error: %v"
,
err
)
}
// Output:
// NAME DESIRED CURRENT AGE CONTAINER(S) IMAGE(S) SELECTOR
// foo 1 1 10y foo,foo2 someimage,someimage2 foo=bar
}
func
ExamplePrintReplicationController
()
{
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
false
,
false
,
[]
string
{})
tf
.
Client
=
&
fake
.
RESTClient
{
Codec
:
codec
,
Client
:
nil
,
}
cmd
:=
NewCmdRun
(
f
,
os
.
Stdin
,
os
.
Stdout
,
os
.
Stderr
)
ctrl
:=
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Labels
:
map
[
string
]
string
{
"foo"
:
"bar"
},
CreationTimestamp
:
unversioned
.
Time
{
Time
:
time
.
Now
()
.
AddDate
(
-
10
,
0
,
0
)},
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
1
,
Selector
:
map
[
string
]
string
{
"foo"
:
"bar"
},
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"foo"
:
"bar"
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"foo"
,
Image
:
"someimage"
,
},
{
Name
:
"foo2"
,
Image
:
"someimage"
,
},
},
},
},
},
},
},
...
@@ -429,8 +481,8 @@ func ExamplePrintReplicationControllerWithWide() {
...
@@ -429,8 +481,8 @@ func ExamplePrintReplicationControllerWithWide() {
fmt
.
Printf
(
"Unexpected error: %v"
,
err
)
fmt
.
Printf
(
"Unexpected error: %v"
,
err
)
}
}
// Output:
// Output:
// NAME DESIRED CURRENT AGE
CONTAINER(S) IMAGE(S) SELECTOR
// NAME DESIRED CURRENT AGE
// foo 1 1 10y
foo someimage foo=bar
// foo 1 1 10y
}
}
func
ExamplePrintPodWithWideFormat
()
{
func
ExamplePrintPodWithWideFormat
()
{
...
...
pkg/kubectl/resource_printer.go
View file @
9788101e
...
@@ -638,22 +638,19 @@ func printPodTemplate(pod *api.PodTemplate, w io.Writer, options PrintOptions) e
...
@@ -638,22 +638,19 @@ func printPodTemplate(pod *api.PodTemplate, w io.Writer, options PrintOptions) e
namespace
:=
pod
.
Namespace
namespace
:=
pod
.
Namespace
containers
:=
pod
.
Template
.
Spec
.
Containers
containers
:=
pod
.
Template
.
Spec
.
Containers
var
firstContainer
api
.
Container
if
len
(
containers
)
>
0
{
firstContainer
,
containers
=
containers
[
0
],
containers
[
1
:
]
}
if
options
.
WithNamespace
{
if
options
.
WithNamespace
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
return
err
return
err
}
}
}
}
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s"
,
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s"
,
name
);
err
!=
nil
{
name
,
return
err
firstContainer
.
Name
,
}
firstContainer
.
Image
,
if
err
:=
layoutContainers
(
containers
,
w
);
err
!=
nil
{
labels
.
FormatLabels
(
pod
.
Template
.
Labels
),
return
err
);
err
!=
nil
{
}
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s"
,
labels
.
FormatLabels
(
pod
.
Template
.
Labels
));
err
!=
nil
{
return
err
return
err
}
}
if
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabels
(
pod
.
Labels
,
options
.
ColumnLabels
));
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabels
(
pod
.
Labels
,
options
.
ColumnLabels
));
err
!=
nil
{
...
@@ -663,20 +660,6 @@ func printPodTemplate(pod *api.PodTemplate, w io.Writer, options PrintOptions) e
...
@@ -663,20 +660,6 @@ func printPodTemplate(pod *api.PodTemplate, w io.Writer, options PrintOptions) e
return
err
return
err
}
}
// Lay out all the other containers on separate lines.
extraLinePrefix
:=
"
\t
"
if
options
.
WithNamespace
{
extraLinePrefix
=
"
\t\t
"
}
for
_
,
container
:=
range
containers
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s%s
\t
%s
\t
%s"
,
extraLinePrefix
,
container
.
Name
,
container
.
Image
,
""
)
if
err
!=
nil
{
return
err
}
if
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabelTabs
(
options
.
ColumnLabels
));
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
...
@@ -689,14 +672,11 @@ func printPodTemplateList(podList *api.PodTemplateList, w io.Writer, options Pri
...
@@ -689,14 +672,11 @@ func printPodTemplateList(podList *api.PodTemplateList, w io.Writer, options Pri
return
nil
return
nil
}
}
// TODO(AdoHe): try to put wide output in a single method
func
printReplicationController
(
controller
*
api
.
ReplicationController
,
w
io
.
Writer
,
options
PrintOptions
)
error
{
func
printReplicationController
(
controller
*
api
.
ReplicationController
,
w
io
.
Writer
,
options
PrintOptions
)
error
{
name
:=
controller
.
Name
name
:=
controller
.
Name
namespace
:=
controller
.
Namespace
namespace
:=
controller
.
Namespace
containers
:=
controller
.
Spec
.
Template
.
Spec
.
Containers
containers
:=
controller
.
Spec
.
Template
.
Spec
.
Containers
var
firstContainer
api
.
Container
if
len
(
containers
)
>
0
{
firstContainer
,
containers
=
containers
[
0
],
containers
[
1
:
]
}
if
options
.
WithNamespace
{
if
options
.
WithNamespace
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
...
@@ -714,12 +694,12 @@ func printReplicationController(controller *api.ReplicationController, w io.Writ
...
@@ -714,12 +694,12 @@ func printReplicationController(controller *api.ReplicationController, w io.Writ
);
err
!=
nil
{
);
err
!=
nil
{
return
err
return
err
}
}
if
options
.
Wide
{
if
options
.
Wide
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s
\t
%s
\t
%s"
,
if
err
:=
layoutContainers
(
containers
,
w
);
err
!=
nil
{
firstContainer
.
Name
,
return
err
firstContainer
.
Image
,
}
labels
.
FormatLabels
(
controller
.
Spec
.
Selector
),
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s"
,
labels
.
FormatLabels
(
controller
.
Spec
.
Selector
));
err
!=
nil
{
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
@@ -730,20 +710,6 @@ func printReplicationController(controller *api.ReplicationController, w io.Writ
...
@@ -730,20 +710,6 @@ func printReplicationController(controller *api.ReplicationController, w io.Writ
return
err
return
err
}
}
// Lay out all the other containers on separate lines.
extraLinePrefix
:=
"
\t
"
if
options
.
WithNamespace
{
extraLinePrefix
=
"
\t\t
"
}
for
_
,
container
:=
range
containers
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s%s
\t
%s
\t
%s
\t
%s"
,
extraLinePrefix
,
container
.
Name
,
container
.
Image
,
""
,
""
)
if
err
!=
nil
{
return
err
}
if
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabelTabs
(
options
.
ColumnLabels
));
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
...
@@ -760,10 +726,6 @@ func printReplicaSet(rs *extensions.ReplicaSet, w io.Writer, options PrintOption
...
@@ -760,10 +726,6 @@ func printReplicaSet(rs *extensions.ReplicaSet, w io.Writer, options PrintOption
name
:=
rs
.
Name
name
:=
rs
.
Name
namespace
:=
rs
.
Namespace
namespace
:=
rs
.
Namespace
containers
:=
rs
.
Spec
.
Template
.
Spec
.
Containers
containers
:=
rs
.
Spec
.
Template
.
Spec
.
Containers
var
firstContainer
api
.
Container
if
len
(
containers
)
>
0
{
firstContainer
,
containers
=
containers
[
0
],
containers
[
1
:
]
}
if
options
.
WithNamespace
{
if
options
.
WithNamespace
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
...
@@ -782,11 +744,10 @@ func printReplicaSet(rs *extensions.ReplicaSet, w io.Writer, options PrintOption
...
@@ -782,11 +744,10 @@ func printReplicaSet(rs *extensions.ReplicaSet, w io.Writer, options PrintOption
return
err
return
err
}
}
if
options
.
Wide
{
if
options
.
Wide
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s
\t
%s
\t
%s"
,
if
err
:=
layoutContainers
(
containers
,
w
);
err
!=
nil
{
firstContainer
.
Name
,
return
err
firstContainer
.
Image
,
}
unversioned
.
FormatLabelSelector
(
rs
.
Spec
.
Selector
),
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s"
,
unversioned
.
FormatLabelSelector
(
rs
.
Spec
.
Selector
));
err
!=
nil
{
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
@@ -797,20 +758,6 @@ func printReplicaSet(rs *extensions.ReplicaSet, w io.Writer, options PrintOption
...
@@ -797,20 +758,6 @@ func printReplicaSet(rs *extensions.ReplicaSet, w io.Writer, options PrintOption
return
err
return
err
}
}
// Lay out all the other containers on separate lines.
extraLinePrefix
:=
"
\t
"
if
options
.
WithNamespace
{
extraLinePrefix
=
"
\t\t
"
}
for
_
,
container
:=
range
containers
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s%s
\t
%s
\t
%s
\t
%s"
,
extraLinePrefix
,
container
.
Name
,
container
.
Image
,
""
,
""
)
if
err
!=
nil
{
return
err
}
if
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabelTabs
(
options
.
ColumnLabels
));
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
...
@@ -827,17 +774,18 @@ func printJob(job *extensions.Job, w io.Writer, options PrintOptions) error {
...
@@ -827,17 +774,18 @@ func printJob(job *extensions.Job, w io.Writer, options PrintOptions) error {
name
:=
job
.
Name
name
:=
job
.
Name
namespace
:=
job
.
Namespace
namespace
:=
job
.
Namespace
containers
:=
job
.
Spec
.
Template
.
Spec
.
Containers
containers
:=
job
.
Spec
.
Template
.
Spec
.
Containers
var
firstContainer
api
.
Container
if
len
(
containers
)
>
0
{
firstContainer
,
containers
=
containers
[
0
],
containers
[
1
:
]
}
if
options
.
WithNamespace
{
if
options
.
WithNamespace
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
return
err
return
err
}
}
}
}
selector
,
_
:=
unversioned
.
LabelSelectorAsSelector
(
job
.
Spec
.
Selector
)
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
job
.
Spec
.
Selector
)
if
err
!=
nil
{
// this shouldn't happen if LabelSelector passed validation
return
err
}
if
job
.
Spec
.
Completions
!=
nil
{
if
job
.
Spec
.
Completions
!=
nil
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%d
\t
%d
\t
%s"
,
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%d
\t
%d
\t
%s"
,
name
,
name
,
...
@@ -858,11 +806,10 @@ func printJob(job *extensions.Job, w io.Writer, options PrintOptions) error {
...
@@ -858,11 +806,10 @@ func printJob(job *extensions.Job, w io.Writer, options PrintOptions) error {
}
}
}
}
if
options
.
Wide
{
if
options
.
Wide
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s
\t
%s
\t
%s"
,
if
err
:=
layoutContainers
(
containers
,
w
);
err
!=
nil
{
firstContainer
.
Name
,
return
err
firstContainer
.
Image
,
}
selector
.
String
(),
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s"
,
selector
.
String
());
err
!=
nil
{
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
@@ -873,20 +820,6 @@ func printJob(job *extensions.Job, w io.Writer, options PrintOptions) error {
...
@@ -873,20 +820,6 @@ func printJob(job *extensions.Job, w io.Writer, options PrintOptions) error {
return
err
return
err
}
}
// Lay out all the other containers on separate lines.
extraLinePrefix
:=
"
\t
"
if
options
.
WithNamespace
{
extraLinePrefix
=
"
\t\t
"
}
for
_
,
container
:=
range
containers
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s%s
\t
%s
\t
%s
\t
%s"
,
extraLinePrefix
,
container
.
Name
,
container
.
Image
,
""
,
""
)
if
err
!=
nil
{
return
err
}
if
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabelTabs
(
options
.
ColumnLabels
));
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
...
@@ -1021,7 +954,8 @@ func printIngress(ingress *extensions.Ingress, w io.Writer, options PrintOptions
...
@@ -1021,7 +954,8 @@ func printIngress(ingress *extensions.Ingress, w io.Writer, options PrintOptions
return
err
return
err
}
}
// Lay out all the rules on separate lines.
// Lay out all the rules on separate lines if use wide output.
// TODO(AdoHe): improve ingress output
extraLinePrefix
:=
""
extraLinePrefix
:=
""
if
options
.
WithNamespace
{
if
options
.
WithNamespace
{
extraLinePrefix
=
"
\t
"
extraLinePrefix
=
"
\t
"
...
@@ -1047,6 +981,7 @@ func printIngress(ingress *extensions.Ingress, w io.Writer, options PrintOptions
...
@@ -1047,6 +981,7 @@ func printIngress(ingress *extensions.Ingress, w io.Writer, options PrintOptions
}
}
}
}
}
}
return
nil
return
nil
}
}
...
@@ -1064,10 +999,6 @@ func printDaemonSet(ds *extensions.DaemonSet, w io.Writer, options PrintOptions)
...
@@ -1064,10 +999,6 @@ func printDaemonSet(ds *extensions.DaemonSet, w io.Writer, options PrintOptions)
namespace
:=
ds
.
Namespace
namespace
:=
ds
.
Namespace
containers
:=
ds
.
Spec
.
Template
.
Spec
.
Containers
containers
:=
ds
.
Spec
.
Template
.
Spec
.
Containers
var
firstContainer
api
.
Container
if
len
(
containers
)
>
0
{
firstContainer
,
containers
=
containers
[
0
],
containers
[
1
:
]
}
if
options
.
WithNamespace
{
if
options
.
WithNamespace
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
...
@@ -1092,11 +1023,10 @@ func printDaemonSet(ds *extensions.DaemonSet, w io.Writer, options PrintOptions)
...
@@ -1092,11 +1023,10 @@ func printDaemonSet(ds *extensions.DaemonSet, w io.Writer, options PrintOptions)
return
err
return
err
}
}
if
options
.
Wide
{
if
options
.
Wide
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s
\t
%s
\t
%s"
,
if
err
:=
layoutContainers
(
containers
,
w
);
err
!=
nil
{
firstContainer
.
Name
,
return
err
firstContainer
.
Image
,
}
selector
,
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s"
,
selector
.
String
());
err
!=
nil
{
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
@@ -1107,20 +1037,6 @@ func printDaemonSet(ds *extensions.DaemonSet, w io.Writer, options PrintOptions)
...
@@ -1107,20 +1037,6 @@ func printDaemonSet(ds *extensions.DaemonSet, w io.Writer, options PrintOptions)
return
err
return
err
}
}
// Lay out all the other containers on separate lines.
extraLinePrefix
:=
"
\t
"
if
options
.
WithNamespace
{
extraLinePrefix
=
"
\t\t
"
}
for
_
,
container
:=
range
containers
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s%s
\t
%s
\t
%s
\t
%s"
,
extraLinePrefix
,
container
.
Name
,
container
.
Image
,
""
,
""
)
if
err
!=
nil
{
return
err
}
if
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabelTabs
(
options
.
ColumnLabels
));
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
...
@@ -1729,6 +1645,26 @@ func appendLabelTabs(columnLabels []string) string {
...
@@ -1729,6 +1645,26 @@ func appendLabelTabs(columnLabels []string) string {
return
buffer
.
String
()
return
buffer
.
String
()
}
}
// Lay out all the containers on one line if use wide output.
func
layoutContainers
(
containers
[]
api
.
Container
,
w
io
.
Writer
)
error
{
var
namesBuffer
bytes
.
Buffer
var
imagesBuffer
bytes
.
Buffer
for
i
,
container
:=
range
containers
{
namesBuffer
.
WriteString
(
container
.
Name
)
imagesBuffer
.
WriteString
(
container
.
Image
)
if
i
!=
len
(
containers
)
-
1
{
namesBuffer
.
WriteString
(
","
)
imagesBuffer
.
WriteString
(
","
)
}
}
_
,
err
:=
fmt
.
Fprintf
(
w
,
"
\t
%s
\t
%s"
,
namesBuffer
.
String
(),
imagesBuffer
.
String
())
if
err
!=
nil
{
return
err
}
return
nil
}
func
formatLabelHeaders
(
columnLabels
[]
string
)
[]
string
{
func
formatLabelHeaders
(
columnLabels
[]
string
)
[]
string
{
formHead
:=
make
([]
string
,
len
(
columnLabels
))
formHead
:=
make
([]
string
,
len
(
columnLabels
))
for
i
,
l
:=
range
columnLabels
{
for
i
,
l
:=
range
columnLabels
{
...
...
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