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
9ad982ef
Commit
9ad982ef
authored
Aug 24, 2015
by
Marcin Wielgus
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12844 from hurf/label_out
Simplify output of 'kubectl label' command
parents
b0354d26
ddf090d8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
56 deletions
+47
-56
label.go
pkg/kubectl/cmd/label.go
+12
-6
label_test.go
pkg/kubectl/cmd/label_test.go
+6
-21
describe.go
pkg/kubectl/describe.go
+12
-12
kubectl.go
pkg/kubectl/kubectl.go
+0
-10
resource_printer.go
pkg/kubectl/resource_printer.go
+8
-7
labels.go
pkg/labels/labels.go
+9
-0
No files found.
pkg/kubectl/cmd/label.go
View file @
9ad982ef
...
@@ -173,7 +173,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
...
@@ -173,7 +173,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
return
err
return
err
}
}
l
abe
ls
,
remove
,
err
:=
parseLabels
(
labelArgs
)
l
b
ls
,
remove
,
err
:=
parseLabels
(
labelArgs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cmdutil
.
UsageError
(
cmd
,
err
.
Error
())
return
cmdutil
.
UsageError
(
cmd
,
err
.
Error
())
}
}
...
@@ -204,7 +204,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
...
@@ -204,7 +204,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
return
err
return
err
}
}
obj
,
err
:=
cmdutil
.
UpdateObject
(
info
,
func
(
obj
runtime
.
Object
)
error
{
obj
,
err
:=
cmdutil
.
UpdateObject
(
info
,
func
(
obj
runtime
.
Object
)
error
{
err
:=
labelFunc
(
obj
,
overwrite
,
resourceVersion
,
l
abe
ls
,
remove
)
err
:=
labelFunc
(
obj
,
overwrite
,
resourceVersion
,
l
b
ls
,
remove
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -214,10 +214,16 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
...
@@ -214,10 +214,16 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
return
err
return
err
}
}
printer
,
err
:=
f
.
PrinterForMapping
(
cmd
,
info
.
Mapping
,
false
)
outputFormat
:=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
if
err
!=
nil
{
if
outputFormat
==
""
{
return
err
cmdutil
.
PrintSuccess
(
mapper
,
false
,
out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
"labeled"
)
}
else
{
printer
,
err
:=
f
.
PrinterForMapping
(
cmd
,
info
.
Mapping
,
false
)
if
err
!=
nil
{
return
err
}
return
printer
.
PrintObj
(
obj
,
out
)
}
}
return
printer
.
PrintObj
(
obj
,
out
)
return
nil
})
})
}
}
pkg/kubectl/cmd/label_test.go
View file @
9ad982ef
...
@@ -325,10 +325,7 @@ func TestLabelErrors(t *testing.T) {
...
@@ -325,10 +325,7 @@ func TestLabelErrors(t *testing.T) {
func
TestLabelForResourceFromFile
(
t
*
testing
.
T
)
{
func
TestLabelForResourceFromFile
(
t
*
testing
.
T
)
{
pods
,
_
,
_
:=
testData
()
pods
,
_
,
_
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
tf
.
Client
=
&
client
.
FakeRESTClient
{
tf
.
Client
=
&
client
.
FakeRESTClient
{
Codec
:
codec
,
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
...
@@ -355,7 +352,6 @@ func TestLabelForResourceFromFile(t *testing.T) {
...
@@ -355,7 +352,6 @@ func TestLabelForResourceFromFile(t *testing.T) {
}
}
}),
}),
}
}
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
tf
.
ClientConfig
=
&
client
.
Config
{
Version
:
testapi
.
Version
()}
tf
.
ClientConfig
=
&
client
.
Config
{
Version
:
testapi
.
Version
()}
...
@@ -363,25 +359,18 @@ func TestLabelForResourceFromFile(t *testing.T) {
...
@@ -363,25 +359,18 @@ func TestLabelForResourceFromFile(t *testing.T) {
cmd
:=
NewCmdLabel
(
f
,
buf
)
cmd
:=
NewCmdLabel
(
f
,
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/cassandra/cassandra.yaml"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/cassandra/cassandra.yaml"
)
cmd
.
SetOutput
(
buf
)
err
:=
RunLabel
(
f
,
buf
,
cmd
,
[]
string
{
"a=b"
})
err
:=
RunLabel
(
f
,
buf
,
cmd
,
[]
string
{
"a=b"
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
if
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
==
nil
{
if
!
strings
.
Contains
(
buf
.
String
(),
"labeled"
)
{
t
.
Errorf
(
"unexpected print to default printer"
)
t
.
Errorf
(
"did not set labels: %s"
,
buf
.
String
())
}
if
!
reflect
.
DeepEqual
(
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
[
0
]
.
(
*
api
.
Pod
)
.
Labels
,
map
[
string
]
string
{
"a"
:
"b"
})
{
t
.
Errorf
(
"did not set labels: %#v"
,
string
(
buf
.
Bytes
()))
}
}
}
}
func
TestLabelMultipleObjects
(
t
*
testing
.
T
)
{
func
TestLabelMultipleObjects
(
t
*
testing
.
T
)
{
pods
,
_
,
_
:=
testData
()
pods
,
_
,
_
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
tf
.
Client
=
&
client
.
FakeRESTClient
{
tf
.
Client
=
&
client
.
FakeRESTClient
{
Codec
:
codec
,
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
...
@@ -412,19 +401,15 @@ func TestLabelMultipleObjects(t *testing.T) {
...
@@ -412,19 +401,15 @@ func TestLabelMultipleObjects(t *testing.T) {
}
}
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
tf
.
ClientConfig
=
&
client
.
Config
{
Version
:
testapi
.
Version
()}
tf
.
ClientConfig
=
&
client
.
Config
{
Version
:
testapi
.
Version
()}
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdLabel
(
f
,
buf
)
cmd
:=
NewCmdLabel
(
f
,
buf
)
cmd
.
Flags
()
.
Set
(
"all"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"all"
,
"true"
)
if
err
:=
RunLabel
(
f
,
buf
,
cmd
,
[]
string
{
"pods"
,
"a=b"
});
err
!=
nil
{
if
err
:=
RunLabel
(
f
,
buf
,
cmd
,
[]
string
{
"pods"
,
"a=b"
});
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
if
strings
.
Count
(
buf
.
String
(),
"labeled"
)
!=
len
(
pods
.
Items
)
{
if
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
==
nil
{
t
.
Errorf
(
"not all labels are set: %s"
,
buf
.
String
())
t
.
Errorf
(
"unexpected non print to default printer"
)
}
if
!
reflect
.
DeepEqual
(
tf
.
Printer
.
(
*
testPrinter
)
.
Objects
[
0
]
.
(
*
api
.
Pod
)
.
Labels
,
map
[
string
]
string
{
"a"
:
"b"
})
{
t
.
Errorf
(
"did not set labels: %#v"
,
string
(
buf
.
Bytes
()))
}
}
}
}
pkg/kubectl/describe.go
View file @
9ad982ef
...
@@ -155,7 +155,7 @@ func (d *NamespaceDescriber) Describe(namespace, name string) (string, error) {
...
@@ -155,7 +155,7 @@ func (d *NamespaceDescriber) Describe(namespace, name string) (string, error) {
func
describeNamespace
(
namespace
*
api
.
Namespace
,
resourceQuotaList
*
api
.
ResourceQuotaList
,
limitRangeList
*
api
.
LimitRangeList
)
(
string
,
error
)
{
func
describeNamespace
(
namespace
*
api
.
Namespace
,
resourceQuotaList
*
api
.
ResourceQuotaList
,
limitRangeList
*
api
.
LimitRangeList
)
(
string
,
error
)
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
namespace
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
namespace
.
Name
)
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
f
ormatLabels
(
namespace
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
namespace
.
Labels
))
fmt
.
Fprintf
(
out
,
"Status:
\t
%s
\n
"
,
string
(
namespace
.
Status
.
Phase
))
fmt
.
Fprintf
(
out
,
"Status:
\t
%s
\n
"
,
string
(
namespace
.
Status
.
Phase
))
if
resourceQuotaList
!=
nil
{
if
resourceQuotaList
!=
nil
{
fmt
.
Fprintf
(
out
,
"
\n
"
)
fmt
.
Fprintf
(
out
,
"
\n
"
)
...
@@ -416,7 +416,7 @@ func describePod(pod *api.Pod, rcs []api.ReplicationController, events *api.Even
...
@@ -416,7 +416,7 @@ func describePod(pod *api.Pod, rcs []api.ReplicationController, events *api.Even
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
pod
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
pod
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Image(s):
\t
%s
\n
"
,
makeImageList
(
&
pod
.
Spec
))
fmt
.
Fprintf
(
out
,
"Image(s):
\t
%s
\n
"
,
makeImageList
(
&
pod
.
Spec
))
fmt
.
Fprintf
(
out
,
"Node:
\t
%s
\n
"
,
pod
.
Spec
.
NodeName
+
"/"
+
pod
.
Status
.
HostIP
)
fmt
.
Fprintf
(
out
,
"Node:
\t
%s
\n
"
,
pod
.
Spec
.
NodeName
+
"/"
+
pod
.
Status
.
HostIP
)
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
f
ormatLabels
(
pod
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
pod
.
Labels
))
if
pod
.
DeletionTimestamp
!=
nil
{
if
pod
.
DeletionTimestamp
!=
nil
{
fmt
.
Fprintf
(
out
,
"Status:
\t
Terminating (expires %s)
\n
"
,
pod
.
DeletionTimestamp
.
Time
.
Format
(
time
.
RFC1123Z
))
fmt
.
Fprintf
(
out
,
"Status:
\t
Terminating (expires %s)
\n
"
,
pod
.
DeletionTimestamp
.
Time
.
Format
(
time
.
RFC1123Z
))
fmt
.
Fprintf
(
out
,
"Termination Grace Period:
\t
%ds
\n
"
,
pod
.
DeletionGracePeriodSeconds
)
fmt
.
Fprintf
(
out
,
"Termination Grace Period:
\t
%ds
\n
"
,
pod
.
DeletionGracePeriodSeconds
)
...
@@ -584,7 +584,7 @@ func (d *PersistentVolumeDescriber) Describe(namespace, name string) (string, er
...
@@ -584,7 +584,7 @@ func (d *PersistentVolumeDescriber) Describe(namespace, name string) (string, er
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
pv
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
pv
.
Name
)
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
f
ormatLabels
(
pv
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
pv
.
Labels
))
fmt
.
Fprintf
(
out
,
"Status:
\t
%s
\n
"
,
pv
.
Status
.
Phase
)
fmt
.
Fprintf
(
out
,
"Status:
\t
%s
\n
"
,
pv
.
Status
.
Phase
)
if
pv
.
Spec
.
ClaimRef
!=
nil
{
if
pv
.
Spec
.
ClaimRef
!=
nil
{
fmt
.
Fprintf
(
out
,
"Claim:
\t
%s
\n
"
,
pv
.
Spec
.
ClaimRef
.
Namespace
+
"/"
+
pv
.
Spec
.
ClaimRef
.
Name
)
fmt
.
Fprintf
(
out
,
"Claim:
\t
%s
\n
"
,
pv
.
Spec
.
ClaimRef
.
Namespace
+
"/"
+
pv
.
Spec
.
ClaimRef
.
Name
)
...
@@ -611,7 +611,7 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string) (strin
...
@@ -611,7 +611,7 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string) (strin
return
""
,
err
return
""
,
err
}
}
labels
:=
f
ormatLabels
(
pvc
.
Labels
)
labels
:=
labels
.
F
ormatLabels
(
pvc
.
Labels
)
storage
:=
pvc
.
Spec
.
Resources
.
Requests
[
api
.
ResourceStorage
]
storage
:=
pvc
.
Spec
.
Resources
.
Requests
[
api
.
ResourceStorage
]
capacity
:=
""
capacity
:=
""
accessModes
:=
""
accessModes
:=
""
...
@@ -756,8 +756,8 @@ func describeReplicationController(controller *api.ReplicationController, events
...
@@ -756,8 +756,8 @@ func describeReplicationController(controller *api.ReplicationController, events
}
else
{
}
else
{
fmt
.
Fprintf
(
out
,
"Image(s):
\t
%s
\n
"
,
"<no template>"
)
fmt
.
Fprintf
(
out
,
"Image(s):
\t
%s
\n
"
,
"<no template>"
)
}
}
fmt
.
Fprintf
(
out
,
"Selector:
\t
%s
\n
"
,
f
ormatLabels
(
controller
.
Spec
.
Selector
))
fmt
.
Fprintf
(
out
,
"Selector:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
controller
.
Spec
.
Selector
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
f
ormatLabels
(
controller
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
controller
.
Labels
))
fmt
.
Fprintf
(
out
,
"Replicas:
\t
%d current / %d desired
\n
"
,
controller
.
Status
.
Replicas
,
controller
.
Spec
.
Replicas
)
fmt
.
Fprintf
(
out
,
"Replicas:
\t
%d current / %d desired
\n
"
,
controller
.
Status
.
Replicas
,
controller
.
Spec
.
Replicas
)
fmt
.
Fprintf
(
out
,
"Pods Status:
\t
%d Running / %d Waiting / %d Succeeded / %d Failed
\n
"
,
running
,
waiting
,
succeeded
,
failed
)
fmt
.
Fprintf
(
out
,
"Pods Status:
\t
%d Running / %d Waiting / %d Succeeded / %d Failed
\n
"
,
running
,
waiting
,
succeeded
,
failed
)
if
controller
.
Spec
.
Template
!=
nil
{
if
controller
.
Spec
.
Template
!=
nil
{
...
@@ -790,8 +790,8 @@ func describeSecret(secret *api.Secret) (string, error) {
...
@@ -790,8 +790,8 @@ func describeSecret(secret *api.Secret) (string, error) {
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
secret
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
secret
.
Name
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
secret
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
secret
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
f
ormatLabels
(
secret
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
secret
.
Labels
))
fmt
.
Fprintf
(
out
,
"Annotations:
\t
%s
\n
"
,
f
ormatLabels
(
secret
.
Annotations
))
fmt
.
Fprintf
(
out
,
"Annotations:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
secret
.
Annotations
))
fmt
.
Fprintf
(
out
,
"
\n
Type:
\t
%s
\n
"
,
secret
.
Type
)
fmt
.
Fprintf
(
out
,
"
\n
Type:
\t
%s
\n
"
,
secret
.
Type
)
...
@@ -851,8 +851,8 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
...
@@ -851,8 +851,8 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
service
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
service
.
Name
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
service
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
service
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
f
ormatLabels
(
service
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
service
.
Labels
))
fmt
.
Fprintf
(
out
,
"Selector:
\t
%s
\n
"
,
f
ormatLabels
(
service
.
Spec
.
Selector
))
fmt
.
Fprintf
(
out
,
"Selector:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
service
.
Spec
.
Selector
))
fmt
.
Fprintf
(
out
,
"Type:
\t
%s
\n
"
,
service
.
Spec
.
Type
)
fmt
.
Fprintf
(
out
,
"Type:
\t
%s
\n
"
,
service
.
Spec
.
Type
)
fmt
.
Fprintf
(
out
,
"IP:
\t
%s
\n
"
,
service
.
Spec
.
ClusterIP
)
fmt
.
Fprintf
(
out
,
"IP:
\t
%s
\n
"
,
service
.
Spec
.
ClusterIP
)
if
len
(
service
.
Status
.
LoadBalancer
.
Ingress
)
>
0
{
if
len
(
service
.
Status
.
LoadBalancer
.
Ingress
)
>
0
{
...
@@ -914,7 +914,7 @@ func describeServiceAccount(serviceAccount *api.ServiceAccount, tokens []api.Sec
...
@@ -914,7 +914,7 @@ func describeServiceAccount(serviceAccount *api.ServiceAccount, tokens []api.Sec
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
serviceAccount
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
serviceAccount
.
Name
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
serviceAccount
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Namespace:
\t
%s
\n
"
,
serviceAccount
.
Namespace
)
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
f
ormatLabels
(
serviceAccount
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
serviceAccount
.
Labels
))
fmt
.
Fprintln
(
out
)
fmt
.
Fprintln
(
out
)
var
(
var
(
...
@@ -1000,7 +1000,7 @@ func (d *NodeDescriber) Describe(namespace, name string) (string, error) {
...
@@ -1000,7 +1000,7 @@ func (d *NodeDescriber) Describe(namespace, name string) (string, error) {
func
describeNode
(
node
*
api
.
Node
,
pods
[]
*
api
.
Pod
,
events
*
api
.
EventList
)
(
string
,
error
)
{
func
describeNode
(
node
*
api
.
Node
,
pods
[]
*
api
.
Pod
,
events
*
api
.
EventList
)
(
string
,
error
)
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
node
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
node
.
Name
)
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
f
ormatLabels
(
node
.
Labels
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
labels
.
F
ormatLabels
(
node
.
Labels
))
fmt
.
Fprintf
(
out
,
"CreationTimestamp:
\t
%s
\n
"
,
node
.
CreationTimestamp
.
Time
.
Format
(
time
.
RFC1123Z
))
fmt
.
Fprintf
(
out
,
"CreationTimestamp:
\t
%s
\n
"
,
node
.
CreationTimestamp
.
Time
.
Format
(
time
.
RFC1123Z
))
if
len
(
node
.
Status
.
Conditions
)
>
0
{
if
len
(
node
.
Status
.
Conditions
)
>
0
{
fmt
.
Fprint
(
out
,
"Conditions:
\n
Type
\t
Status
\t
LastHeartbeatTime
\t
LastTransitionTime
\t
Reason
\t
Message
\n
"
)
fmt
.
Fprint
(
out
,
"Conditions:
\n
Type
\t
Status
\t
LastHeartbeatTime
\t
LastTransitionTime
\t
Reason
\t
Message
\n
"
)
...
...
pkg/kubectl/kubectl.go
View file @
9ad982ef
...
@@ -23,7 +23,6 @@ import (
...
@@ -23,7 +23,6 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/labels"
)
)
const
kubectlAnnotationPrefix
=
"kubectl.kubernetes.io/"
const
kubectlAnnotationPrefix
=
"kubectl.kubernetes.io/"
...
@@ -32,15 +31,6 @@ type NamespaceInfo struct {
...
@@ -32,15 +31,6 @@ type NamespaceInfo struct {
Namespace
string
Namespace
string
}
}
// TODO Move to labels package.
func
formatLabels
(
labelMap
map
[
string
]
string
)
string
{
l
:=
labels
.
Set
(
labelMap
)
.
String
()
if
l
==
""
{
l
=
"<none>"
}
return
l
}
func
listOfImages
(
spec
*
api
.
PodSpec
)
[]
string
{
func
listOfImages
(
spec
*
api
.
PodSpec
)
[]
string
{
var
images
[]
string
var
images
[]
string
for
_
,
container
:=
range
spec
.
Containers
{
for
_
,
container
:=
range
spec
.
Containers
{
...
...
pkg/kubectl/resource_printer.go
View file @
9ad982ef
...
@@ -34,6 +34,7 @@ import (
...
@@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/expapi"
"k8s.io/kubernetes/pkg/expapi"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/jsonpath"
"k8s.io/kubernetes/pkg/util/jsonpath"
...
@@ -500,7 +501,7 @@ func printPodTemplate(pod *api.PodTemplate, w io.Writer, withNamespace bool, wid
...
@@ -500,7 +501,7 @@ func printPodTemplate(pod *api.PodTemplate, w io.Writer, withNamespace bool, wid
name
,
name
,
firstContainer
.
Name
,
firstContainer
.
Name
,
firstContainer
.
Image
,
firstContainer
.
Image
,
f
ormatLabels
(
pod
.
Template
.
Labels
),
labels
.
F
ormatLabels
(
pod
.
Template
.
Labels
),
);
err
!=
nil
{
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -553,7 +554,7 @@ func printReplicationController(controller *api.ReplicationController, w io.Writ
...
@@ -553,7 +554,7 @@ func printReplicationController(controller *api.ReplicationController, w io.Writ
name
,
name
,
firstContainer
.
Name
,
firstContainer
.
Name
,
firstContainer
.
Image
,
firstContainer
.
Image
,
f
ormatLabels
(
controller
.
Spec
.
Selector
),
labels
.
F
ormatLabels
(
controller
.
Spec
.
Selector
),
controller
.
Spec
.
Replicas
,
controller
.
Spec
.
Replicas
,
translateTimestamp
(
controller
.
CreationTimestamp
),
translateTimestamp
(
controller
.
CreationTimestamp
),
);
err
!=
nil
{
);
err
!=
nil
{
...
@@ -643,7 +644,7 @@ func printService(svc *api.Service, w io.Writer, withNamespace bool, wide bool,
...
@@ -643,7 +644,7 @@ func printService(svc *api.Service, w io.Writer, withNamespace bool, wide bool,
internalIP
,
internalIP
,
externalIP
,
externalIP
,
makePortString
(
svc
.
Spec
.
Ports
),
makePortString
(
svc
.
Spec
.
Ports
),
f
ormatLabels
(
svc
.
Spec
.
Selector
),
labels
.
F
ormatLabels
(
svc
.
Spec
.
Selector
),
translateTimestamp
(
svc
.
CreationTimestamp
),
translateTimestamp
(
svc
.
CreationTimestamp
),
);
err
!=
nil
{
);
err
!=
nil
{
return
err
return
err
...
@@ -693,7 +694,7 @@ func printNamespace(item *api.Namespace, w io.Writer, withNamespace bool, wide b
...
@@ -693,7 +694,7 @@ func printNamespace(item *api.Namespace, w io.Writer, withNamespace bool, wide b
return
fmt
.
Errorf
(
"namespace is not namespaced"
)
return
fmt
.
Errorf
(
"namespace is not namespaced"
)
}
}
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s"
,
item
.
Name
,
f
ormatLabels
(
item
.
Labels
),
item
.
Status
.
Phase
,
translateTimestamp
(
item
.
CreationTimestamp
));
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s"
,
item
.
Name
,
labels
.
F
ormatLabels
(
item
.
Labels
),
item
.
Status
.
Phase
,
translateTimestamp
(
item
.
CreationTimestamp
));
err
!=
nil
{
return
err
return
err
}
}
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabels
(
item
.
Labels
,
columnLabels
))
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabels
(
item
.
Labels
,
columnLabels
))
...
@@ -788,7 +789,7 @@ func printNode(node *api.Node, w io.Writer, withNamespace bool, wide bool, showA
...
@@ -788,7 +789,7 @@ func printNode(node *api.Node, w io.Writer, withNamespace bool, wide bool, showA
status
=
append
(
status
,
"SchedulingDisabled"
)
status
=
append
(
status
,
"SchedulingDisabled"
)
}
}
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s"
,
node
.
Name
,
f
ormatLabels
(
node
.
Labels
),
strings
.
Join
(
status
,
","
),
translateTimestamp
(
node
.
CreationTimestamp
));
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s"
,
node
.
Name
,
labels
.
F
ormatLabels
(
node
.
Labels
),
strings
.
Join
(
status
,
","
),
translateTimestamp
(
node
.
CreationTimestamp
));
err
!=
nil
{
return
err
return
err
}
}
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabels
(
node
.
Labels
,
columnLabels
))
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabels
(
node
.
Labels
,
columnLabels
))
...
@@ -824,7 +825,7 @@ func printPersistentVolume(pv *api.PersistentVolume, w io.Writer, withNamespace
...
@@ -824,7 +825,7 @@ func printPersistentVolume(pv *api.PersistentVolume, w io.Writer, withNamespace
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s"
,
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s"
,
name
,
name
,
f
ormatLabels
(
pv
.
Labels
),
labels
.
F
ormatLabels
(
pv
.
Labels
),
aSize
,
modesStr
,
aSize
,
modesStr
,
pv
.
Status
.
Phase
,
pv
.
Status
.
Phase
,
claimRefUID
,
claimRefUID
,
...
@@ -856,7 +857,7 @@ func printPersistentVolumeClaim(pvc *api.PersistentVolumeClaim, w io.Writer, wit
...
@@ -856,7 +857,7 @@ func printPersistentVolumeClaim(pvc *api.PersistentVolumeClaim, w io.Writer, wit
}
}
}
}
labels
:=
f
ormatLabels
(
pvc
.
Labels
)
labels
:=
labels
.
F
ormatLabels
(
pvc
.
Labels
)
phase
:=
pvc
.
Status
.
Phase
phase
:=
pvc
.
Status
.
Phase
storage
:=
pvc
.
Spec
.
Resources
.
Requests
[
api
.
ResourceStorage
]
storage
:=
pvc
.
Spec
.
Resources
.
Requests
[
api
.
ResourceStorage
]
capacity
:=
""
capacity
:=
""
...
...
pkg/labels/labels.go
View file @
9ad982ef
...
@@ -60,3 +60,12 @@ func (ls Set) Get(label string) string {
...
@@ -60,3 +60,12 @@ func (ls Set) Get(label string) string {
func
(
ls
Set
)
AsSelector
()
Selector
{
func
(
ls
Set
)
AsSelector
()
Selector
{
return
SelectorFromSet
(
ls
)
return
SelectorFromSet
(
ls
)
}
}
// FormatLables convert label map into plain string
func
FormatLabels
(
labelMap
map
[
string
]
string
)
string
{
l
:=
Set
(
labelMap
)
.
String
()
if
l
==
""
{
l
=
"<none>"
}
return
l
}
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