Skip to content

Commit

Permalink
Add support for --abort.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandburns committed May 2, 2015
1 parent 262c34e commit e05539a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions contrib/completions/bash/kubectl
Expand Up @@ -419,6 +419,7 @@ _kubectl_rolling-update()
two_word_flags+=("-o")
flags+=("--output-version=")
flags+=("--poll-interval=")
flags+=("--rollback")
flags+=("--template=")
two_word_flags+=("-t")
flags+=("--timeout=")
Expand Down
2 changes: 1 addition & 1 deletion docs/design/simple-rolling-update.md
Expand Up @@ -38,7 +38,7 @@ it is assumed that the rollout is nearly completed, and ```foo-next``` is rename
### Aborting a rollout
Abort is assumed to want to reverse a rollout in progress.

```kubectl rolling-update rc foo [foo-v2] --abort```
```kubectl rolling-update rc foo [foo-v2] --rollback```

This is really just semantic sugar for:

Expand Down
3 changes: 2 additions & 1 deletion docs/kubectl_rolling-update.md
Expand Up @@ -45,6 +45,7 @@ $ kubectl rolling-update frontend --image=image:v2
-o, --output="": Output format. One of: json|yaml|template|templatefile.
--output-version="": Output the formatted object with the given version (default api-version).
--poll-interval="3s": Time delay between polling controller status after update. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
--rollback=false: If true, this is a request to abort an existing rollout that is partially rolled out. It effectively reverses current and next and runs a rollout
-t, --template="": Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]
--timeout="5m0s": Max time to wait for a controller to update before giving up. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
--update-period="1m0s": Time to wait between updating pods. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
Expand Down Expand Up @@ -83,4 +84,4 @@ $ kubectl rolling-update frontend --image=image:v2
### SEE ALSO
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager

###### Auto generated by spf13/cobra at 2015-04-29 15:25:11.031878187 +0000 UTC
###### Auto generated by spf13/cobra at 2015-05-02 00:22:29.503205238 +0000 UTC
4 changes: 4 additions & 0 deletions docs/man/man1/kubectl-rolling-update.1
Expand Up @@ -58,6 +58,10 @@ existing controller and overwrite at least one (common) label in its replicaSele
\fB\-\-poll\-interval\fP="3s"
Time delay between polling controller status after update. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

.PP
\fB\-\-rollback\fP=false
If true, this is a request to abort an existing rollout that is partially rolled out. It effectively reverses current and next and runs a rollout

.PP
\fB\-t\fP, \fB\-\-template\fP=""
Template string or path to template file to use when \-o=template or \-o=templatefile. The template format is golang templates [
Expand Down
9 changes: 7 additions & 2 deletions pkg/kubectl/cmd/rollingupdate.go
Expand Up @@ -81,6 +81,7 @@ func NewCmdRollingUpdate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmd.Flags().String("image", "", "Image to upgrade the controller to. Can not be used with --filename/-f")
cmd.Flags().String("deployment-label-key", "deployment", "The key to use to differentiate between two different controllers, default 'deployment'. Only relevant when --image is specified, ignored otherwise")
cmd.Flags().Bool("dry-run", false, "If true, print out the changes that would be made, but don't actually make them.")
cmd.Flags().Bool("rollback", false, "If true, this is a request to abort an existing rollout that is partially rolled out. It effectively reverses current and next and runs a rollout")
cmdutil.AddPrinterFlags(cmd)
return cmd
}
Expand Down Expand Up @@ -250,15 +251,19 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
if keepOldName {
updateCleanupPolicy = kubectl.RenameRollingUpdateCleanupPolicy
}
err = updater.Update(&kubectl.RollingUpdaterConfig{
config := &kubectl.RollingUpdaterConfig{
Out: out,
OldRc: oldRc,
NewRc: newRc,
UpdatePeriod: period,
Interval: interval,
Timeout: timeout,
CleanupPolicy: updateCleanupPolicy,
})
}
if cmdutil.GetFlagBool(cmd, "rollback") {
kubectl.AbortRollingUpdate(config)
}
err = updater.Update(config)
if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/kubectl/rolling_updater.go
Expand Up @@ -85,6 +85,21 @@ const (
nextControllerAnnotation = kubectlAnnotationPrefix + "next-controller-id"
)

func AbortRollingUpdate(c *RollingUpdaterConfig) {
// Swap the controllers
tmp := c.OldRc
c.OldRc = c.NewRc
c.NewRc = tmp

desiredSize, found := c.OldRc.Annotations[desiredReplicasAnnotation]
if found {
if c.NewRc.Annotations == nil {
c.NewRc.Annotations = map[string]string{}
}
c.NewRc.Annotations[desiredReplicasAnnotation] = desiredSize
}
}

func GetNextControllerAnnotation(rc *api.ReplicationController) (string, bool) {
res, found := rc.Annotations[nextControllerAnnotation]
return res, found
Expand Down

0 comments on commit e05539a

Please sign in to comment.