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
cbd10dbf
Commit
cbd10dbf
authored
Sep 25, 2015
by
wulonghui
Committed by
wulonghui
Oct 08, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update rollback process
parent
4cb021f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
19 deletions
+47
-19
rollingupdate.go
pkg/kubectl/cmd/rollingupdate.go
+46
-18
rollingupdate_test.go
pkg/kubectl/cmd/rollingupdate_test.go
+1
-1
No files found.
pkg/kubectl/cmd/rollingupdate.go
View file @
cbd10dbf
...
...
@@ -100,47 +100,62 @@ func NewCmdRollingUpdate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
return
cmd
}
func
validateArguments
(
cmd
*
cobra
.
Command
,
filenames
,
args
[]
string
)
(
deploymentKey
,
filename
,
image
,
oldName
string
,
err
error
)
{
deploymentKey
=
cmdutil
.
GetFlagString
(
cmd
,
"deployment-label-key"
)
image
=
cmdutil
.
GetFlagString
(
cmd
,
"image"
)
filename
=
""
func
validateArguments
(
cmd
*
cobra
.
Command
,
filenames
,
args
[]
string
)
error
{
deploymentKey
:
=
cmdutil
.
GetFlagString
(
cmd
,
"deployment-label-key"
)
image
:
=
cmdutil
.
GetFlagString
(
cmd
,
"image"
)
rollback
:=
cmdutil
.
GetFlagBool
(
cmd
,
"rollback"
)
if
len
(
deploymentKey
)
==
0
{
return
""
,
""
,
""
,
""
,
cmdutil
.
UsageError
(
cmd
,
"--deployment-label-key can not be empty"
)
return
cmdutil
.
UsageError
(
cmd
,
"--deployment-label-key can not be empty"
)
}
if
len
(
filenames
)
>
1
{
return
""
,
""
,
""
,
""
,
cmdutil
.
UsageError
(
cmd
,
"May only specific
y a single filename for new controller"
)
return
cmdutil
.
UsageError
(
cmd
,
"May only specif
y a single filename for new controller"
)
}
if
len
(
filenames
)
>
0
{
filename
=
filenames
[
0
]
}
if
len
(
filenames
)
==
0
&&
len
(
image
)
==
0
{
return
""
,
""
,
""
,
""
,
cmdutil
.
UsageError
(
cmd
,
"Must specify --filename or --image for new controller"
)
}
if
len
(
filenames
)
!=
0
&&
len
(
image
)
!=
0
{
return
""
,
""
,
""
,
""
,
cmdutil
.
UsageError
(
cmd
,
"--filename and --image can not both be specified"
)
if
!
rollback
{
if
len
(
filenames
)
==
0
&&
len
(
image
)
==
0
{
return
cmdutil
.
UsageError
(
cmd
,
"Must specify --filename or --image for new controller"
)
}
if
len
(
filenames
)
!=
0
&&
len
(
image
)
!=
0
{
return
cmdutil
.
UsageError
(
cmd
,
"--filename and --image can not both be specified"
)
}
}
else
{
if
len
(
filenames
)
!=
0
||
len
(
image
)
!=
0
{
return
cmdutil
.
UsageError
(
cmd
,
"Don't specify --filename or --image on rollback"
)
}
}
if
len
(
args
)
<
1
{
return
""
,
""
,
""
,
""
,
cmdutil
.
UsageError
(
cmd
,
"Must specify the controller to update"
)
return
cmdutil
.
UsageError
(
cmd
,
"Must specify the controller to update"
)
}
return
deploymentKey
,
filename
,
image
,
args
[
0
],
nil
return
nil
}
func
RunRollingUpdate
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
,
options
*
RollingUpdateOptions
)
error
{
if
len
(
os
.
Args
)
>
1
&&
os
.
Args
[
1
]
==
"rollingupdate"
{
printDeprecationWarning
(
"rolling-update"
,
"rollingupdate"
)
}
deploymentKey
,
filename
,
image
,
oldName
,
err
:=
validateArguments
(
cmd
,
options
.
Filenames
,
args
)
err
:=
validateArguments
(
cmd
,
options
.
Filenames
,
args
)
if
err
!=
nil
{
return
err
}
deploymentKey
:=
cmdutil
.
GetFlagString
(
cmd
,
"deployment-label-key"
)
filename
:=
""
image
:=
cmdutil
.
GetFlagString
(
cmd
,
"image"
)
oldName
:=
args
[
0
]
rollback
:=
cmdutil
.
GetFlagBool
(
cmd
,
"rollback"
)
period
:=
cmdutil
.
GetFlagDuration
(
cmd
,
"update-period"
)
interval
:=
cmdutil
.
GetFlagDuration
(
cmd
,
"poll-interval"
)
timeout
:=
cmdutil
.
GetFlagDuration
(
cmd
,
"timeout"
)
dryrun
:=
cmdutil
.
GetFlagBool
(
cmd
,
"dry-run"
)
outputFormat
:=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
if
len
(
options
.
Filenames
)
>
0
{
filename
=
options
.
Filenames
[
0
]
}
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
if
err
!=
nil
{
return
err
...
...
@@ -238,6 +253,19 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
return
err
}
}
if
rollback
{
keepOldName
=
len
(
args
)
==
1
newName
:=
findNewName
(
args
,
oldRc
)
if
newRc
,
err
=
kubectl
.
LoadExistingNextReplicationController
(
client
,
cmdNamespace
,
newName
);
err
!=
nil
{
return
err
}
if
newRc
==
nil
{
return
cmdutil
.
UsageError
(
cmd
,
"Could not find %s to rollback.
\n
"
,
newName
)
}
}
if
oldName
==
newRc
.
Name
{
return
cmdutil
.
UsageError
(
cmd
,
"%s cannot have the same name as the existing ReplicationController %s"
,
filename
,
oldName
)
...
...
@@ -295,7 +323,7 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
MaxUnavailable
:
util
.
NewIntOrStringFromInt
(
0
),
MaxSurge
:
util
.
NewIntOrStringFromInt
(
1
),
}
if
cmdutil
.
GetFlagBool
(
cmd
,
"rollback"
)
{
if
rollback
{
err
=
kubectl
.
AbortRollingUpdate
(
config
)
if
err
!=
nil
{
return
err
...
...
pkg/kubectl/cmd/rollingupdate_test.go
View file @
cbd10dbf
...
...
@@ -79,7 +79,7 @@ func TestValidateArgs(t *testing.T) {
cmd
.
Flags
()
.
Set
(
key
,
val
)
}
}
_
,
_
,
_
,
_
,
err
:=
validateArguments
(
cmd
,
test
.
filenames
,
test
.
args
)
err
:=
validateArguments
(
cmd
,
test
.
filenames
,
test
.
args
)
if
err
!=
nil
&&
!
test
.
expectErr
{
t
.
Errorf
(
"unexpected error: %v (%s)"
,
err
,
test
.
testName
)
}
...
...
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