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
6eaab223
Commit
6eaab223
authored
Nov 07, 2016
by
juanvallejo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add --dry-run opt to `kubectl set image`
This patch adds a `--dry-run` option to `kubectl set image...`
parent
45a436ac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
3 deletions
+63
-3
BUILD
pkg/kubectl/cmd/set/BUILD
+5
-1
set_image.go
pkg/kubectl/cmd/set/set_image.go
+11
-2
set_test.go
pkg/kubectl/cmd/set/set_test.go
+47
-0
No files found.
pkg/kubectl/cmd/set/BUILD
View file @
6eaab223
...
@@ -36,7 +36,10 @@ go_library(
...
@@ -36,7 +36,10 @@ go_library(
go_test(
go_test(
name = "go_default_test",
name = "go_default_test",
srcs = ["set_image_test.go"],
srcs = [
"set_image_test.go",
"set_test.go",
],
data = [
data = [
"//examples:config",
"//examples:config",
],
],
...
@@ -50,5 +53,6 @@ go_test(
...
@@ -50,5 +53,6 @@ go_test(
"//pkg/kubectl/cmd/testing:go_default_library",
"//pkg/kubectl/cmd/testing:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/resource:go_default_library",
"//pkg/kubectl/resource:go_default_library",
"//vendor:github.com/spf13/cobra",
],
],
)
)
pkg/kubectl/cmd/set/set_image.go
View file @
6eaab223
...
@@ -42,9 +42,11 @@ type ImageOptions struct {
...
@@ -42,9 +42,11 @@ type ImageOptions struct {
Selector
string
Selector
string
Out
io
.
Writer
Out
io
.
Writer
Err
io
.
Writer
Err
io
.
Writer
DryRun
bool
ShortOutput
bool
ShortOutput
bool
All
bool
All
bool
Record
bool
Record
bool
Output
string
ChangeCause
string
ChangeCause
string
Local
bool
Local
bool
Cmd
*
cobra
.
Command
Cmd
*
cobra
.
Command
...
@@ -104,6 +106,7 @@ func NewCmdImage(f cmdutil.Factory, out, err io.Writer) *cobra.Command {
...
@@ -104,6 +106,7 @@ func NewCmdImage(f cmdutil.Factory, out, err io.Writer) *cobra.Command {
cmd
.
Flags
()
.
StringVarP
(
&
options
.
Selector
,
"selector"
,
"l"
,
""
,
"Selector (label query) to filter on, supports '=', '==', and '!='."
)
cmd
.
Flags
()
.
StringVarP
(
&
options
.
Selector
,
"selector"
,
"l"
,
""
,
"Selector (label query) to filter on, supports '=', '==', and '!='."
)
cmd
.
Flags
()
.
BoolVar
(
&
options
.
Local
,
"local"
,
false
,
"If true, set image will NOT contact api-server but run locally."
)
cmd
.
Flags
()
.
BoolVar
(
&
options
.
Local
,
"local"
,
false
,
"If true, set image will NOT contact api-server but run locally."
)
cmdutil
.
AddRecordFlag
(
cmd
)
cmdutil
.
AddRecordFlag
(
cmd
)
cmdutil
.
AddDryRunFlag
(
cmd
)
return
cmd
return
cmd
}
}
...
@@ -115,6 +118,8 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
...
@@ -115,6 +118,8 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
o
.
Record
=
cmdutil
.
GetRecordFlag
(
cmd
)
o
.
Record
=
cmdutil
.
GetRecordFlag
(
cmd
)
o
.
ChangeCause
=
f
.
Command
()
o
.
ChangeCause
=
f
.
Command
()
o
.
PrintObject
=
f
.
PrintObject
o
.
PrintObject
=
f
.
PrintObject
o
.
DryRun
=
cmdutil
.
GetDryRunFlag
(
cmd
)
o
.
Output
=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
o
.
Cmd
=
cmd
o
.
Cmd
=
cmd
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
...
@@ -198,7 +203,7 @@ func (o *ImageOptions) Run() error {
...
@@ -198,7 +203,7 @@ func (o *ImageOptions) Run() error {
continue
continue
}
}
if
o
.
Local
{
if
o
.
PrintObject
!=
nil
&&
(
o
.
Local
||
o
.
DryRun
)
{
return
o
.
PrintObject
(
o
.
Cmd
,
o
.
Mapper
,
info
.
Object
,
o
.
Out
)
return
o
.
PrintObject
(
o
.
Cmd
,
o
.
Mapper
,
info
.
Object
,
o
.
Out
)
}
}
...
@@ -220,7 +225,11 @@ func (o *ImageOptions) Run() error {
...
@@ -220,7 +225,11 @@ func (o *ImageOptions) Run() error {
}
}
info
.
Refresh
(
obj
,
true
)
info
.
Refresh
(
obj
,
true
)
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
o
.
ShortOutput
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"image updated"
)
if
len
(
o
.
Output
)
>
0
{
return
o
.
PrintObject
(
o
.
Cmd
,
o
.
Mapper
,
obj
,
o
.
Out
)
}
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
o
.
ShortOutput
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
o
.
DryRun
,
"image updated"
)
}
}
return
utilerrors
.
NewAggregate
(
allErrs
)
return
utilerrors
.
NewAggregate
(
allErrs
)
}
}
...
...
pkg/kubectl/cmd/set/set_test.go
0 → 100644
View file @
6eaab223
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
set
import
(
"bytes"
"testing"
"github.com/spf13/cobra"
clientcmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
func
TestLocalAndDryRunFlags
(
t
*
testing
.
T
)
{
out
:=
&
bytes
.
Buffer
{}
errout
:=
&
bytes
.
Buffer
{}
f
:=
clientcmdutil
.
NewFactory
(
nil
)
setCmd
:=
NewCmdSet
(
f
,
out
,
errout
)
ensureLocalAndDryRunFlagsOnChildren
(
t
,
setCmd
,
""
)
}
func
ensureLocalAndDryRunFlagsOnChildren
(
t
*
testing
.
T
,
c
*
cobra
.
Command
,
prefix
string
)
{
for
_
,
cmd
:=
range
c
.
Commands
()
{
name
:=
prefix
+
cmd
.
Name
()
if
localFlag
:=
cmd
.
Flag
(
"local"
);
localFlag
==
nil
{
t
.
Errorf
(
"Command %s does not implement the --local flag"
,
name
)
}
if
dryRunFlag
:=
cmd
.
Flag
(
"dry-run"
);
dryRunFlag
==
nil
{
t
.
Errorf
(
"Command %s does not implement the --dry-run flag"
,
name
)
}
ensureLocalAndDryRunFlagsOnChildren
(
t
,
cmd
,
name
+
"."
)
}
}
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