From cc9d04647a68cf49e66bf26f10908387b99dae1a Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Wed, 15 Feb 2017 14:53:58 -0800 Subject: [PATCH] Add support for the "rollback" failure action Signed-off-by: Aaron Lehmann --- api/swagger.yaml | 1 + api/types/swarm/service.go | 8 ++++++++ cli/command/service/opts.go | 2 +- daemon/cluster/convert/service.go | 10 ++++++++++ docs/api/version-history.md | 1 + docs/reference/commandline/service_create.md | 2 +- docs/reference/commandline/service_update.md | 2 +- 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/api/swagger.yaml b/api/swagger.yaml index 77c39ff323..29c9941efb 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -2256,6 +2256,7 @@ definitions: enum: - "continue" - "pause" + - "rollback" Monitor: description: "Amount of time to monitor each updated task for failures, in nanoseconds." type: "integer" diff --git a/api/types/swarm/service.go b/api/types/swarm/service.go index 04f59de862..0a909c38b7 100644 --- a/api/types/swarm/service.go +++ b/api/types/swarm/service.go @@ -45,6 +45,12 @@ const ( UpdateStatePaused UpdateState = "paused" // UpdateStateCompleted is the completed state. UpdateStateCompleted UpdateState = "completed" + // UpdateStateRollbackStarted is the state with a rollback in progress. + UpdateStateRollbackStarted UpdateState = "rollback_started" + // UpdateStateRollbackPaused is the state with a rollback in progress. + UpdateStateRollbackPaused UpdateState = "rollback_paused" + // UpdateStateRollbackCompleted is the state with a rollback in progress. + UpdateStateRollbackCompleted UpdateState = "rollback_completed" ) // UpdateStatus reports the status of a service update. @@ -68,6 +74,8 @@ const ( UpdateFailureActionPause = "pause" // UpdateFailureActionContinue CONTINUE UpdateFailureActionContinue = "continue" + // UpdateFailureActionRollback ROLLBACK + UpdateFailureActionRollback = "rollback" ) // UpdateConfig represents the update configuration. diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index 36ab2c6301..b9ae89ad0c 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -487,7 +487,7 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) { flags.DurationVar(&opts.update.delay, flagUpdateDelay, time.Duration(0), "Delay between updates (ns|us|ms|s|m|h) (default 0s)") flags.DurationVar(&opts.update.monitor, flagUpdateMonitor, time.Duration(0), "Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)") flags.SetAnnotation(flagUpdateMonitor, "version", []string{"1.25"}) - flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", `Action on update failure ("pause"|"continue")`) + flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", `Action on update failure ("pause"|"continue"|"rollback")`) flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update") flags.SetAnnotation(flagUpdateMaxFailureRatio, "version", []string{"1.25"}) diff --git a/daemon/cluster/convert/service.go b/daemon/cluster/convert/service.go index 515b46a1bc..91c96eec73 100644 --- a/daemon/cluster/convert/service.go +++ b/daemon/cluster/convert/service.go @@ -35,6 +35,12 @@ func ServiceFromGRPC(s swarmapi.Service) types.Service { service.UpdateStatus.State = types.UpdateStatePaused case swarmapi.UpdateStatus_COMPLETED: service.UpdateStatus.State = types.UpdateStateCompleted + case swarmapi.UpdateStatus_ROLLBACK_STARTED: + service.UpdateStatus.State = types.UpdateStateRollbackStarted + case swarmapi.UpdateStatus_ROLLBACK_PAUSED: + service.UpdateStatus.State = types.UpdateStateRollbackPaused + case swarmapi.UpdateStatus_ROLLBACK_COMPLETED: + service.UpdateStatus.State = types.UpdateStateRollbackCompleted } startedAt, _ := gogotypes.TimestampFromProto(s.UpdateStatus.StartedAt) @@ -102,6 +108,8 @@ func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) *types.ServiceSpec { convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionPause case swarmapi.UpdateConfig_CONTINUE: convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionContinue + case swarmapi.UpdateConfig_ROLLBACK: + convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionRollback } } @@ -187,6 +195,8 @@ func ServiceSpecToGRPC(s types.ServiceSpec) (swarmapi.ServiceSpec, error) { failureAction = swarmapi.UpdateConfig_PAUSE case types.UpdateFailureActionContinue: failureAction = swarmapi.UpdateConfig_CONTINUE + case types.UpdateFailureActionRollback: + failureAction = swarmapi.UpdateConfig_ROLLBACK default: return swarmapi.ServiceSpec{}, fmt.Errorf("unrecognized update failure action %s", s.UpdateConfig.FailureAction) } diff --git a/docs/api/version-history.md b/docs/api/version-history.md index 51e438e6c8..a802170b68 100644 --- a/docs/api/version-history.md +++ b/docs/api/version-history.md @@ -22,6 +22,7 @@ keywords: "API, Docker, rcli, REST, documentation" * `GET /containers/json` now supports `publish` and `expose` filters to filter containers that expose or publish certain ports. * `POST /services/create` and `POST /services/(id or name)/update` now accept the `ReadOnly` parameter, which mounts the container's root filesystem as read only. * `POST /build` now accepts `extrahosts` parameter to specify a host to ip mapping to use during the build. +* `POST /services/create` and `POST /services/(id or name)/update` now accept a `rollback` value for `FailureAction`. ## v1.26 API changes diff --git a/docs/reference/commandline/service_create.md b/docs/reference/commandline/service_create.md index a27199215c..ba06b3f33e 100644 --- a/docs/reference/commandline/service_create.md +++ b/docs/reference/commandline/service_create.md @@ -62,7 +62,7 @@ Options: --stop-signal string Signal to stop the container -t, --tty Allocate a pseudo-TTY --update-delay duration Delay between updates (ns|us|ms|s|m|h) (default 0s) - --update-failure-action string Action on update failure ("pause"|"continue") (default "pause") + --update-failure-action string Action on update failure ("pause"|"continue"|"rollback") (default "pause") --update-max-failure-ratio float Failure rate to tolerate during an update --update-monitor duration Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s) --update-parallelism uint Maximum number of tasks updated simultaneously (0 to update all at once) (default 1) diff --git a/docs/reference/commandline/service_update.md b/docs/reference/commandline/service_update.md index 160ed53120..6a6a589a5d 100644 --- a/docs/reference/commandline/service_update.md +++ b/docs/reference/commandline/service_update.md @@ -75,7 +75,7 @@ Options: --stop-signal string Signal to stop the container -t, --tty Allocate a pseudo-TTY --update-delay duration Delay between updates (ns|us|ms|s|m|h) (default 0s) - --update-failure-action string Action on update failure ("pause"|"continue") (default "pause") + --update-failure-action string Action on update failure ("pause"|"continue"|"rollback") (default "pause") --update-max-failure-ratio float Failure rate to tolerate during an update --update-monitor duration Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s) --update-parallelism uint Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)