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
2a202cf4
Unverified
Commit
2a202cf4
authored
Apr 06, 2018
by
juanvallejo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update PrintFlags#Complete to receive string template
parent
b8dc2064
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
54 additions
and
64 deletions
+54
-64
set_env.go
pkg/kubectl/cmd/set/set_env.go
+7
-3
set_env_test.go
pkg/kubectl/cmd/set/set_env_test.go
+3
-3
set_image.go
pkg/kubectl/cmd/set/set_image.go
+8
-6
set_image_test.go
pkg/kubectl/cmd/set/set_image_test.go
+4
-4
set_resources.go
pkg/kubectl/cmd/set/set_resources.go
+3
-3
set_resources_test.go
pkg/kubectl/cmd/set/set_resources_test.go
+3
-3
set_selector.go
pkg/kubectl/cmd/set/set_selector.go
+7
-7
set_serviceaccount.go
pkg/kubectl/cmd/set/set_serviceaccount.go
+3
-3
set_serviceaccount_test.go
pkg/kubectl/cmd/set/set_serviceaccount_test.go
+4
-4
set_subject.go
pkg/kubectl/cmd/set/set_subject.go
+7
-7
flags.go
pkg/printers/flags.go
+3
-3
name_flags.go
pkg/printers/name_flags.go
+1
-10
name_flags_test.go
pkg/printers/name_flags_test.go
+0
-7
printers.go
pkg/printers/printers.go
+1
-1
No files found.
pkg/kubectl/cmd/set/set_env.go
View file @
2a202cf4
...
@@ -215,13 +215,17 @@ func (o *EnvOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
...
@@ -215,13 +215,17 @@ func (o *EnvOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
o
.
Resources
=
resources
o
.
Resources
=
resources
o
.
Cmd
=
cmd
o
.
Cmd
=
cmd
o
.
PrintFlags
.
Complete
(
o
.
DryRun
)
if
o
.
DryRun
{
// TODO(juanvallejo): This can be cleaned up even further by creating
// a PrintFlags struct that binds the --dry-run flag, and whose
// ToPrinter method returns a printer that understands how to print
// this success message.
o
.
PrintFlags
.
Complete
(
"%s (dry run)"
)
}
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
return
printer
.
PrintObj
(
obj
,
o
.
Out
)
return
printer
.
PrintObj
(
obj
,
o
.
Out
)
}
}
...
...
pkg/kubectl/cmd/set/set_env_test.go
View file @
2a202cf4
...
@@ -74,7 +74,7 @@ func TestSetEnvLocal(t *testing.T) {
...
@@ -74,7 +74,7 @@ func TestSetEnvLocal(t *testing.T) {
opts
:=
EnvOptions
{
opts
:=
EnvOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
@@ -123,7 +123,7 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
...
@@ -123,7 +123,7 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
opts
:=
EnvOptions
{
opts
:=
EnvOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
@@ -514,7 +514,7 @@ func TestSetEnvRemote(t *testing.T) {
...
@@ -514,7 +514,7 @@ func TestSetEnvRemote(t *testing.T) {
opts
:=
EnvOptions
{
opts
:=
EnvOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
...
pkg/kubectl/cmd/set/set_image.go
View file @
2a202cf4
...
@@ -127,7 +127,9 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
...
@@ -127,7 +127,9 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
o
.
ResolveImage
=
f
.
ResolveImage
o
.
ResolveImage
=
f
.
ResolveImage
o
.
Cmd
=
cmd
o
.
Cmd
=
cmd
o
.
PrintFlags
.
Complete
(
o
.
DryRun
)
if
o
.
DryRun
{
o
.
PrintFlags
.
Complete
(
"%s (dry run)"
)
}
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -250,6 +252,11 @@ func (o *ImageOptions) Run() error {
...
@@ -250,6 +252,11 @@ func (o *ImageOptions) Run() error {
continue
continue
}
}
// no changes
if
string
(
patch
.
Patch
)
==
"{}"
||
len
(
patch
.
Patch
)
==
0
{
continue
}
if
o
.
Local
||
o
.
DryRun
{
if
o
.
Local
||
o
.
DryRun
{
if
err
:=
o
.
PrintObj
(
patch
.
Info
.
AsVersioned
());
err
!=
nil
{
if
err
:=
o
.
PrintObj
(
patch
.
Info
.
AsVersioned
());
err
!=
nil
{
return
err
return
err
...
@@ -257,11 +264,6 @@ func (o *ImageOptions) Run() error {
...
@@ -257,11 +264,6 @@ func (o *ImageOptions) Run() error {
continue
continue
}
}
// no changes
if
string
(
patch
.
Patch
)
==
"{}"
||
len
(
patch
.
Patch
)
==
0
{
continue
}
// patch the change
// patch the change
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
types
.
StrategicMergePatchType
,
patch
.
Patch
)
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
types
.
StrategicMergePatchType
,
patch
.
Patch
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/cmd/set/set_image_test.go
View file @
2a202cf4
...
@@ -74,7 +74,7 @@ func TestImageLocal(t *testing.T) {
...
@@ -74,7 +74,7 @@ func TestImageLocal(t *testing.T) {
opts
:=
ImageOptions
{
opts
:=
ImageOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
@@ -100,7 +100,7 @@ func TestImageLocal(t *testing.T) {
...
@@ -100,7 +100,7 @@ func TestImageLocal(t *testing.T) {
func
TestSetImageValidation
(
t
*
testing
.
T
)
{
func
TestSetImageValidation
(
t
*
testing
.
T
)
{
printFlags
:=
&
printers
.
PrintFlags
{
printFlags
:=
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
}
}
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
...
@@ -196,7 +196,7 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
...
@@ -196,7 +196,7 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
opts
:=
ImageOptions
{
opts
:=
ImageOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
@@ -590,7 +590,7 @@ func TestSetImageRemote(t *testing.T) {
...
@@ -590,7 +590,7 @@ func TestSetImageRemote(t *testing.T) {
opts
:=
ImageOptions
{
opts
:=
ImageOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
...
pkg/kubectl/cmd/set/set_resources.go
View file @
2a202cf4
...
@@ -148,13 +148,13 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
...
@@ -148,13 +148,13 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
o
.
Cmd
=
cmd
o
.
Cmd
=
cmd
o
.
DryRun
=
cmdutil
.
GetDryRunFlag
(
o
.
Cmd
)
o
.
DryRun
=
cmdutil
.
GetDryRunFlag
(
o
.
Cmd
)
o
.
PrintFlags
.
Complete
(
o
.
DryRun
)
if
o
.
DryRun
{
o
.
PrintFlags
.
Complete
(
"%s (dry run)"
)
}
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
return
printer
.
PrintObj
(
obj
,
o
.
Out
)
return
printer
.
PrintObj
(
obj
,
o
.
Out
)
}
}
...
...
pkg/kubectl/cmd/set/set_resources_test.go
View file @
2a202cf4
...
@@ -73,7 +73,7 @@ func TestResourcesLocal(t *testing.T) {
...
@@ -73,7 +73,7 @@ func TestResourcesLocal(t *testing.T) {
opts
:=
ResourcesOptions
{
opts
:=
ResourcesOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
@@ -127,7 +127,7 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
...
@@ -127,7 +127,7 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
opts
:=
ResourcesOptions
{
opts
:=
ResourcesOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
@@ -508,7 +508,7 @@ func TestSetResourcesRemote(t *testing.T) {
...
@@ -508,7 +508,7 @@ func TestSetResourcesRemote(t *testing.T) {
opts
:=
ResourcesOptions
{
opts
:=
ResourcesOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
...
pkg/kubectl/cmd/set/set_selector.go
View file @
2a202cf4
...
@@ -53,7 +53,6 @@ type SelectorOptions struct {
...
@@ -53,7 +53,6 @@ type SelectorOptions struct {
selector
*
metav1
.
LabelSelector
selector
*
metav1
.
LabelSelector
out
io
.
Writer
out
io
.
Writer
PrintObject
func
(
obj
runtime
.
Object
)
error
ClientForMapping
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
ClientForMapping
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
PrintObj
func
(
runtime
.
Object
)
error
PrintObj
func
(
runtime
.
Object
)
error
...
@@ -119,8 +118,6 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
...
@@ -119,8 +118,6 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
o
.
dryrun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
dryrun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
PrintFlags
.
Complete
(
o
.
dryrun
)
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -158,14 +155,17 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
...
@@ -158,14 +155,17 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
}
}
}
}
if
o
.
dryrun
{
o
.
PrintFlags
.
Complete
(
"%s (dry run)"
)
}
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
o
.
PrintObject
=
func
(
obj
runtime
.
Object
)
error
{
return
printer
.
PrintObj
(
obj
,
o
.
out
)
return
printer
.
PrintObj
(
obj
,
o
.
out
)
}
}
o
.
ClientForMapping
=
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
{
o
.
ClientForMapping
=
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
{
return
f
.
ClientForMapping
(
mapping
)
return
f
.
ClientForMapping
(
mapping
)
}
}
...
@@ -208,7 +208,7 @@ func (o *SelectorOptions) RunSelector() error {
...
@@ -208,7 +208,7 @@ func (o *SelectorOptions) RunSelector() error {
return
patch
.
Err
return
patch
.
Err
}
}
if
o
.
local
||
o
.
dryrun
{
if
o
.
local
||
o
.
dryrun
{
return
o
.
PrintObj
ect
(
info
.
Object
)
return
o
.
PrintObj
(
info
.
Object
)
}
}
patched
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
types
.
StrategicMergePatchType
,
patch
.
Patch
)
patched
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
types
.
StrategicMergePatchType
,
patch
.
Patch
)
...
@@ -225,7 +225,7 @@ func (o *SelectorOptions) RunSelector() error {
...
@@ -225,7 +225,7 @@ func (o *SelectorOptions) RunSelector() error {
}
}
info
.
Refresh
(
patched
,
true
)
info
.
Refresh
(
patched
,
true
)
return
o
.
PrintObj
ect
(
patch
.
Info
.
AsVersioned
())
return
o
.
PrintObj
(
patch
.
Info
.
AsVersioned
())
})
})
}
}
...
...
pkg/kubectl/cmd/set/set_serviceaccount.go
View file @
2a202cf4
...
@@ -120,13 +120,13 @@ func (saConfig *serviceAccountConfig) Complete(f cmdutil.Factory, cmd *cobra.Com
...
@@ -120,13 +120,13 @@ func (saConfig *serviceAccountConfig) Complete(f cmdutil.Factory, cmd *cobra.Com
saConfig
.
updatePodSpecForObject
=
f
.
UpdatePodSpecForObject
saConfig
.
updatePodSpecForObject
=
f
.
UpdatePodSpecForObject
saConfig
.
cmd
=
cmd
saConfig
.
cmd
=
cmd
saConfig
.
PrintFlags
.
Complete
(
saConfig
.
dryRun
)
if
saConfig
.
dryRun
{
saConfig
.
PrintFlags
.
Complete
(
"%s (dry run)"
)
}
printer
,
err
:=
saConfig
.
PrintFlags
.
ToPrinter
()
printer
,
err
:=
saConfig
.
PrintFlags
.
ToPrinter
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
saConfig
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
saConfig
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
return
printer
.
PrintObj
(
obj
,
saConfig
.
out
)
return
printer
.
PrintObj
(
obj
,
saConfig
.
out
)
}
}
...
...
pkg/kubectl/cmd/set/set_serviceaccount_test.go
View file @
2a202cf4
...
@@ -92,7 +92,7 @@ func TestSetServiceAccountLocal(t *testing.T) {
...
@@ -92,7 +92,7 @@ func TestSetServiceAccountLocal(t *testing.T) {
saConfig
:=
serviceAccountConfig
{
saConfig
:=
serviceAccountConfig
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
@@ -136,7 +136,7 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
...
@@ -136,7 +136,7 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
opts
:=
serviceAccountConfig
{
opts
:=
serviceAccountConfig
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
@@ -380,7 +380,7 @@ func TestSetServiceAccountRemote(t *testing.T) {
...
@@ -380,7 +380,7 @@ func TestSetServiceAccountRemote(t *testing.T) {
saConfig
:=
serviceAccountConfig
{
saConfig
:=
serviceAccountConfig
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
@@ -427,7 +427,7 @@ func TestServiceAccountValidation(t *testing.T) {
...
@@ -427,7 +427,7 @@ func TestServiceAccountValidation(t *testing.T) {
saConfig
:=
&
serviceAccountConfig
{
saConfig
:=
&
serviceAccountConfig
{
PrintFlags
:
&
printers
.
PrintFlags
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
},
},
...
...
pkg/kubectl/cmd/set/set_subject.go
View file @
2a202cf4
...
@@ -74,7 +74,7 @@ type SubjectOptions struct {
...
@@ -74,7 +74,7 @@ type SubjectOptions struct {
Groups
[]
string
Groups
[]
string
ServiceAccounts
[]
string
ServiceAccounts
[]
string
PrintObj
ect
func
(
obj
runtime
.
Object
)
error
PrintObj
func
(
obj
runtime
.
Object
)
error
}
}
func
NewCmdSubject
(
f
cmdutil
.
Factory
,
out
io
.
Writer
,
errOut
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdSubject
(
f
cmdutil
.
Factory
,
out
io
.
Writer
,
errOut
io
.
Writer
)
*
cobra
.
Command
{
...
@@ -117,14 +117,14 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
...
@@ -117,14 +117,14 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
o
.
Output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
Output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
DryRun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
DryRun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
PrintFlags
.
Complete
(
o
.
DryRun
)
if
o
.
DryRun
{
o
.
PrintFlags
.
Complete
(
"%s (dry run)"
)
}
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
o
.
PrintObject
=
func
(
obj
runtime
.
Object
)
error
{
return
printer
.
PrintObj
(
obj
,
o
.
Out
)
return
printer
.
PrintObj
(
obj
,
o
.
Out
)
}
}
...
@@ -251,7 +251,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
...
@@ -251,7 +251,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
}
}
if
o
.
Local
||
o
.
DryRun
{
if
o
.
Local
||
o
.
DryRun
{
if
err
:=
o
.
PrintObj
ect
(
info
.
Object
);
err
!=
nil
{
if
err
:=
o
.
PrintObj
(
info
.
Object
);
err
!=
nil
{
return
err
return
err
}
}
continue
continue
...
@@ -264,7 +264,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
...
@@ -264,7 +264,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
}
}
info
.
Refresh
(
obj
,
true
)
info
.
Refresh
(
obj
,
true
)
return
o
.
PrintObj
ect
(
info
.
AsVersioned
())
return
o
.
PrintObj
(
info
.
AsVersioned
())
}
}
return
utilerrors
.
NewAggregate
(
allErrs
)
return
utilerrors
.
NewAggregate
(
allErrs
)
}
}
...
...
pkg/printers/flags.go
View file @
2a202cf4
...
@@ -45,8 +45,8 @@ type PrintFlags struct {
...
@@ -45,8 +45,8 @@ type PrintFlags struct {
OutputFormat
*
string
OutputFormat
*
string
}
}
func
(
f
*
PrintFlags
)
Complete
(
dryRun
bool
)
error
{
func
(
f
*
PrintFlags
)
Complete
(
messageTemplate
string
)
error
{
f
.
NamePrintFlags
.
DryRun
=
dryRun
f
.
NamePrintFlags
.
Operation
=
fmt
.
Sprintf
(
messageTemplate
,
f
.
NamePrintFlags
.
Operation
)
return
nil
return
nil
}
}
...
@@ -80,6 +80,6 @@ func NewPrintFlags(operation string) *PrintFlags {
...
@@ -80,6 +80,6 @@ func NewPrintFlags(operation string) *PrintFlags {
OutputFormat
:
&
outputFormat
,
OutputFormat
:
&
outputFormat
,
JSONYamlPrintFlags
:
NewJSONYamlPrintFlags
(),
JSONYamlPrintFlags
:
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
NewNamePrintFlags
(
operation
,
false
),
NamePrintFlags
:
NewNamePrintFlags
(
operation
),
}
}
}
}
pkg/printers/name_flags.go
View file @
2a202cf4
...
@@ -31,10 +31,6 @@ import (
...
@@ -31,10 +31,6 @@ import (
// a resource's fully-qualified Kind.group/name, or a successful
// a resource's fully-qualified Kind.group/name, or a successful
// message about that resource if an Operation is provided.
// message about that resource if an Operation is provided.
type
NamePrintFlags
struct
{
type
NamePrintFlags
struct
{
// DryRun indicates whether the "(dry run)" message
// should be appended to the finalized "successful"
// message printed about an action on an object.
DryRun
bool
// Operation describes the name of the action that
// Operation describes the name of the action that
// took place on an object, to be included in the
// took place on an object, to be included in the
// finalized "successful" message.
// finalized "successful" message.
...
@@ -53,10 +49,6 @@ func (f *NamePrintFlags) ToPrinter(outputFormat string) (ResourcePrinter, error)
...
@@ -53,10 +49,6 @@ func (f *NamePrintFlags) ToPrinter(outputFormat string) (ResourcePrinter, error)
Decoders
:
decoders
,
Decoders
:
decoders
,
}
}
if
f
.
DryRun
{
namePrinter
.
Operation
=
namePrinter
.
Operation
+
" (dry run)"
}
outputFormat
=
strings
.
ToLower
(
outputFormat
)
outputFormat
=
strings
.
ToLower
(
outputFormat
)
switch
outputFormat
{
switch
outputFormat
{
case
"name"
:
case
"name"
:
...
@@ -75,9 +67,8 @@ func (f *NamePrintFlags) AddFlags(c *cobra.Command) {}
...
@@ -75,9 +67,8 @@ func (f *NamePrintFlags) AddFlags(c *cobra.Command) {}
// NewNamePrintFlags returns flags associated with
// NewNamePrintFlags returns flags associated with
// --name printing, with default values set.
// --name printing, with default values set.
func
NewNamePrintFlags
(
operation
string
,
dryRun
bool
)
*
NamePrintFlags
{
func
NewNamePrintFlags
(
operation
string
)
*
NamePrintFlags
{
return
&
NamePrintFlags
{
return
&
NamePrintFlags
{
Operation
:
operation
,
Operation
:
operation
,
DryRun
:
dryRun
,
}
}
}
}
pkg/printers/name_flags_test.go
View file @
2a202cf4
...
@@ -50,12 +50,6 @@ func TestNamePrinterSupportsExpectedFormats(t *testing.T) {
...
@@ -50,12 +50,6 @@ func TestNamePrinterSupportsExpectedFormats(t *testing.T) {
expectedOutput
:
"pod/foo"
,
expectedOutput
:
"pod/foo"
,
},
},
{
{
name
:
"empty output format and an operation prints success message with dry run"
,
operation
:
"patched"
,
dryRun
:
true
,
expectedOutput
:
"pod/foo patched (dry run)"
,
},
{
name
:
"operation and no valid
\"
name
\"
output does not match a printer"
,
name
:
"operation and no valid
\"
name
\"
output does not match a printer"
,
operation
:
"patched"
,
operation
:
"patched"
,
outputFormat
:
"invalid"
,
outputFormat
:
"invalid"
,
...
@@ -83,7 +77,6 @@ func TestNamePrinterSupportsExpectedFormats(t *testing.T) {
...
@@ -83,7 +77,6 @@ func TestNamePrinterSupportsExpectedFormats(t *testing.T) {
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
printFlags
:=
printers
.
NamePrintFlags
{
printFlags
:=
printers
.
NamePrintFlags
{
Operation
:
tc
.
operation
,
Operation
:
tc
.
operation
,
DryRun
:
tc
.
dryRun
,
}
}
p
,
err
:=
printFlags
.
ToPrinter
(
tc
.
outputFormat
)
p
,
err
:=
printFlags
.
ToPrinter
(
tc
.
outputFormat
)
...
...
pkg/printers/printers.go
View file @
2a202cf4
...
@@ -42,7 +42,7 @@ func GetStandardPrinter(typer runtime.ObjectTyper, encoder runtime.Encoder, deco
...
@@ -42,7 +42,7 @@ func GetStandardPrinter(typer runtime.ObjectTyper, encoder runtime.Encoder, deco
printer
=
p
printer
=
p
case
"name"
:
case
"name"
:
nameFlags
:=
NewNamePrintFlags
(
""
,
false
)
nameFlags
:=
NewNamePrintFlags
(
""
)
namePrinter
,
err
:=
nameFlags
.
ToPrinter
(
format
)
namePrinter
,
err
:=
nameFlags
.
ToPrinter
(
format
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
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