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
o
.
Resources
=
resources
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
()
if
err
!=
nil
{
return
err
}
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
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) {
opts
:=
EnvOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
@@ -123,7 +123,7 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
opts
:=
EnvOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
@@ -514,7 +514,7 @@ func TestSetEnvRemote(t *testing.T) {
opts
:=
EnvOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
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
o
.
ResolveImage
=
f
.
ResolveImage
o
.
Cmd
=
cmd
o
.
PrintFlags
.
Complete
(
o
.
DryRun
)
if
o
.
DryRun
{
o
.
PrintFlags
.
Complete
(
"%s (dry run)"
)
}
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
if
err
!=
nil
{
...
...
@@ -250,6 +252,11 @@ func (o *ImageOptions) Run() error {
continue
}
// no changes
if
string
(
patch
.
Patch
)
==
"{}"
||
len
(
patch
.
Patch
)
==
0
{
continue
}
if
o
.
Local
||
o
.
DryRun
{
if
err
:=
o
.
PrintObj
(
patch
.
Info
.
AsVersioned
());
err
!=
nil
{
return
err
...
...
@@ -257,11 +264,6 @@ func (o *ImageOptions) Run() error {
continue
}
// no changes
if
string
(
patch
.
Patch
)
==
"{}"
||
len
(
patch
.
Patch
)
==
0
{
continue
}
// patch the change
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
types
.
StrategicMergePatchType
,
patch
.
Patch
)
if
err
!=
nil
{
...
...
pkg/kubectl/cmd/set/set_image_test.go
View file @
2a202cf4
...
...
@@ -74,7 +74,7 @@ func TestImageLocal(t *testing.T) {
opts
:=
ImageOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
@@ -100,7 +100,7 @@ func TestImageLocal(t *testing.T) {
func
TestSetImageValidation
(
t
*
testing
.
T
)
{
printFlags
:=
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
}
testCases
:=
[]
struct
{
...
...
@@ -196,7 +196,7 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
opts
:=
ImageOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
@@ -590,7 +590,7 @@ func TestSetImageRemote(t *testing.T) {
opts
:=
ImageOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
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
o
.
Cmd
=
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
()
if
err
!=
nil
{
return
err
}
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
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) {
opts
:=
ResourcesOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
@@ -127,7 +127,7 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
opts
:=
ResourcesOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
@@ -508,7 +508,7 @@ func TestSetResourcesRemote(t *testing.T) {
opts
:=
ResourcesOptions
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
pkg/kubectl/cmd/set/set_selector.go
View file @
2a202cf4
...
...
@@ -53,7 +53,6 @@ type SelectorOptions struct {
selector
*
metav1
.
LabelSelector
out
io
.
Writer
PrintObject
func
(
obj
runtime
.
Object
)
error
ClientForMapping
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
PrintObj
func
(
runtime
.
Object
)
error
...
...
@@ -119,8 +118,6 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
o
.
dryrun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
PrintFlags
.
Complete
(
o
.
dryrun
)
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
if
err
!=
nil
{
return
err
...
...
@@ -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
()
if
err
!=
nil
{
return
err
}
o
.
PrintObject
=
func
(
obj
runtime
.
Object
)
error
{
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
return
printer
.
PrintObj
(
obj
,
o
.
out
)
}
o
.
ClientForMapping
=
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
{
return
f
.
ClientForMapping
(
mapping
)
}
...
...
@@ -208,7 +208,7 @@ func (o *SelectorOptions) RunSelector() error {
return
patch
.
Err
}
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
)
...
...
@@ -225,7 +225,7 @@ func (o *SelectorOptions) RunSelector() error {
}
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
saConfig
.
updatePodSpecForObject
=
f
.
UpdatePodSpecForObject
saConfig
.
cmd
=
cmd
saConfig
.
PrintFlags
.
Complete
(
saConfig
.
dryRun
)
if
saConfig
.
dryRun
{
saConfig
.
PrintFlags
.
Complete
(
"%s (dry run)"
)
}
printer
,
err
:=
saConfig
.
PrintFlags
.
ToPrinter
()
if
err
!=
nil
{
return
err
}
saConfig
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
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) {
saConfig
:=
serviceAccountConfig
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
@@ -136,7 +136,7 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
opts
:=
serviceAccountConfig
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
@@ -380,7 +380,7 @@ func TestSetServiceAccountRemote(t *testing.T) {
saConfig
:=
serviceAccountConfig
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
@@ -427,7 +427,7 @@ func TestServiceAccountValidation(t *testing.T) {
saConfig
:=
&
serviceAccountConfig
{
PrintFlags
:
&
printers
.
PrintFlags
{
JSONYamlPrintFlags
:
printers
.
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
,
false
),
NamePrintFlags
:
printers
.
NewNamePrintFlags
(
""
),
OutputFormat
:
&
outputFormat
,
},
...
...
pkg/kubectl/cmd/set/set_subject.go
View file @
2a202cf4
...
...
@@ -74,7 +74,7 @@ type SubjectOptions struct {
Groups
[]
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
{
...
...
@@ -117,14 +117,14 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
o
.
Output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
DryRun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
PrintFlags
.
Complete
(
o
.
DryRun
)
if
o
.
DryRun
{
o
.
PrintFlags
.
Complete
(
"%s (dry run)"
)
}
printer
,
err
:=
o
.
PrintFlags
.
ToPrinter
()
if
err
!=
nil
{
return
err
}
o
.
PrintObject
=
func
(
obj
runtime
.
Object
)
error
{
o
.
PrintObj
=
func
(
obj
runtime
.
Object
)
error
{
return
printer
.
PrintObj
(
obj
,
o
.
Out
)
}
...
...
@@ -251,7 +251,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
}
if
o
.
Local
||
o
.
DryRun
{
if
err
:=
o
.
PrintObj
ect
(
info
.
Object
);
err
!=
nil
{
if
err
:=
o
.
PrintObj
(
info
.
Object
);
err
!=
nil
{
return
err
}
continue
...
...
@@ -264,7 +264,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
}
info
.
Refresh
(
obj
,
true
)
return
o
.
PrintObj
ect
(
info
.
AsVersioned
())
return
o
.
PrintObj
(
info
.
AsVersioned
())
}
return
utilerrors
.
NewAggregate
(
allErrs
)
}
...
...
pkg/printers/flags.go
View file @
2a202cf4
...
...
@@ -45,8 +45,8 @@ type PrintFlags struct {
OutputFormat
*
string
}
func
(
f
*
PrintFlags
)
Complete
(
dryRun
bool
)
error
{
f
.
NamePrintFlags
.
DryRun
=
dryRun
func
(
f
*
PrintFlags
)
Complete
(
messageTemplate
string
)
error
{
f
.
NamePrintFlags
.
Operation
=
fmt
.
Sprintf
(
messageTemplate
,
f
.
NamePrintFlags
.
Operation
)
return
nil
}
...
...
@@ -80,6 +80,6 @@ func NewPrintFlags(operation string) *PrintFlags {
OutputFormat
:
&
outputFormat
,
JSONYamlPrintFlags
:
NewJSONYamlPrintFlags
(),
NamePrintFlags
:
NewNamePrintFlags
(
operation
,
false
),
NamePrintFlags
:
NewNamePrintFlags
(
operation
),
}
}
pkg/printers/name_flags.go
View file @
2a202cf4
...
...
@@ -31,10 +31,6 @@ import (
// a resource's fully-qualified Kind.group/name, or a successful
// message about that resource if an Operation is provided.
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
// took place on an object, to be included in the
// finalized "successful" message.
...
...
@@ -53,10 +49,6 @@ func (f *NamePrintFlags) ToPrinter(outputFormat string) (ResourcePrinter, error)
Decoders
:
decoders
,
}
if
f
.
DryRun
{
namePrinter
.
Operation
=
namePrinter
.
Operation
+
" (dry run)"
}
outputFormat
=
strings
.
ToLower
(
outputFormat
)
switch
outputFormat
{
case
"name"
:
...
...
@@ -75,9 +67,8 @@ func (f *NamePrintFlags) AddFlags(c *cobra.Command) {}
// NewNamePrintFlags returns flags associated with
// --name printing, with default values set.
func
NewNamePrintFlags
(
operation
string
,
dryRun
bool
)
*
NamePrintFlags
{
func
NewNamePrintFlags
(
operation
string
)
*
NamePrintFlags
{
return
&
NamePrintFlags
{
Operation
:
operation
,
DryRun
:
dryRun
,
}
}
pkg/printers/name_flags_test.go
View file @
2a202cf4
...
...
@@ -50,12 +50,6 @@ func TestNamePrinterSupportsExpectedFormats(t *testing.T) {
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"
,
operation
:
"patched"
,
outputFormat
:
"invalid"
,
...
...
@@ -83,7 +77,6 @@ func TestNamePrinterSupportsExpectedFormats(t *testing.T) {
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
printFlags
:=
printers
.
NamePrintFlags
{
Operation
:
tc
.
operation
,
DryRun
:
tc
.
dryRun
,
}
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
printer
=
p
case
"name"
:
nameFlags
:=
NewNamePrintFlags
(
""
,
false
)
nameFlags
:=
NewNamePrintFlags
(
""
)
namePrinter
,
err
:=
nameFlags
.
ToPrinter
(
format
)
if
err
!=
nil
{
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