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
ddf090d8
Commit
ddf090d8
authored
Aug 16, 2015
by
hurf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change default output of 'label' command
Using simple, human understandable output instead of the form of 'kubectl get' command.
parent
36987e9d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
27 deletions
+18
-27
label.go
pkg/kubectl/cmd/label.go
+12
-6
label_test.go
pkg/kubectl/cmd/label_test.go
+6
-21
No files found.
pkg/kubectl/cmd/label.go
View file @
ddf090d8
...
@@ -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 @
ddf090d8
...
@@ -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
()))
}
}
}
}
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