Browse code

Add support for rollback flags

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2017/02/16 09:04:30
Showing 10 changed files
... ...
@@ -2265,6 +2265,32 @@ definitions:
2265 2265
             description: "The fraction of tasks that may fail during an update before the failure action is invoked, specified as a floating point number between 0 and 1."
2266 2266
             type: "number"
2267 2267
             default: 0
2268
+      RollbackConfig:
2269
+        description: "Specification for the rollback strategy of the service."
2270
+        type: "object"
2271
+        properties:
2272
+          Parallelism:
2273
+            description: "Maximum number of tasks to be rolled back in one iteration (0 means unlimited parallelism)."
2274
+            type: "integer"
2275
+            format: "int64"
2276
+          Delay:
2277
+            description: "Amount of time between rollback iterations, in nanoseconds."
2278
+            type: "integer"
2279
+            format: "int64"
2280
+          FailureAction:
2281
+            description: "Action to take if an rolled back task fails to run, or stops running during the rollback."
2282
+            type: "string"
2283
+            enum:
2284
+              - "continue"
2285
+              - "pause"
2286
+          Monitor:
2287
+            description: "Amount of time to monitor each rolled back task for failures, in nanoseconds."
2288
+            type: "integer"
2289
+            format: "int64"
2290
+          MaxFailureRatio:
2291
+            description: "The fraction of tasks that may fail during a rollback before the failure action is invoked, specified as a floating point number between 0 and 1."
2292
+            type: "number"
2293
+            default: 0
2268 2294
       Networks:
2269 2295
         description: "Array of network names or IDs to attach the service to."
2270 2296
         type: "array"
... ...
@@ -2387,6 +2413,13 @@ definitions:
2387 2387
             Replicas: 1
2388 2388
         UpdateConfig:
2389 2389
           Parallelism: 1
2390
+          Delay: 1000000000
2391
+          FailureAction: "pause"
2392
+          Monitor: 15000000000
2393
+          MaxFailureRatio: 0.15
2394
+        RollbackConfig:
2395
+          Parallelism: 1
2396
+          Delay: 1000000000
2390 2397
           FailureAction: "pause"
2391 2398
           Monitor: 15000000000
2392 2399
           MaxFailureRatio: 0.15
... ...
@@ -7436,9 +7469,17 @@ paths:
7436 7436
                     Replicated:
7437 7437
                       Replicas: 4
7438 7438
                   UpdateConfig:
7439
-                    Delay: 30000000000
7440 7439
                     Parallelism: 2
7440
+                    Delay: 1000000000
7441 7441
                     FailureAction: "pause"
7442
+                    Monitor: 15000000000
7443
+                    MaxFailureRatio: 0.15
7444
+                  RollbackConfig:
7445
+                    Parallelism: 1
7446
+                    Delay: 1000000000
7447
+                    FailureAction: "pause"
7448
+                    Monitor: 15000000000
7449
+                    MaxFailureRatio: 0.15
7442 7450
                   EndpointSpec:
7443 7451
                     Ports:
7444 7452
                       -
... ...
@@ -7564,7 +7605,15 @@ paths:
7564 7564
                     Replicated:
7565 7565
                       Replicas: 1
7566 7566
                   UpdateConfig:
7567
+                    Parallelism: 2
7568
+                    Delay: 1000000000
7569
+                    FailureAction: "pause"
7570
+                    Monitor: 15000000000
7571
+                    MaxFailureRatio: 0.15
7572
+                  RollbackConfig:
7567 7573
                     Parallelism: 1
7574
+                    Delay: 1000000000
7575
+                    FailureAction: "pause"
7568 7576
                     Monitor: 15000000000
7569 7577
                     MaxFailureRatio: 0.15
7570 7578
                   EndpointSpec:
... ...
@@ -18,9 +18,10 @@ type ServiceSpec struct {
18 18
 
19 19
 	// TaskTemplate defines how the service should construct new tasks when
20 20
 	// orchestrating this service.
21
-	TaskTemplate TaskSpec      `json:",omitempty"`
22
-	Mode         ServiceMode   `json:",omitempty"`
23
-	UpdateConfig *UpdateConfig `json:",omitempty"`
21
+	TaskTemplate   TaskSpec      `json:",omitempty"`
22
+	Mode           ServiceMode   `json:",omitempty"`
23
+	UpdateConfig   *UpdateConfig `json:",omitempty"`
24
+	RollbackConfig *UpdateConfig `json:",omitempty"`
24 25
 
25 26
 	// Networks field in ServiceSpec is deprecated. The
26 27
 	// same field in TaskSpec should be used instead.
... ...
@@ -57,6 +57,18 @@ UpdateConfig:
57 57
 {{- end }}
58 58
  Max failure ratio: {{ .UpdateMaxFailureRatio }}
59 59
 {{- end }}
60
+{{- if .HasRollbackConfig }}
61
+RollbackConfig:
62
+ Parallelism:	{{ .RollbackParallelism }}
63
+{{- if .HasRollbackDelay}}
64
+ Delay:		{{ .RollbackDelay }}
65
+{{- end }}
66
+ On failure:	{{ .RollbackOnFailure }}
67
+{{- if .HasRollbackMonitor}}
68
+ Monitoring Period: {{ .RollbackMonitor }}
69
+{{- end }}
70
+ Max failure ratio: {{ .RollbackMaxFailureRatio }}
71
+{{- end }}
60 72
 ContainerSpec:
61 73
  Image:		{{ .ContainerImage }}
62 74
 {{- if .ContainerArgs }}
... ...
@@ -259,6 +271,38 @@ func (ctx *serviceInspectContext) UpdateMaxFailureRatio() float32 {
259 259
 	return ctx.Service.Spec.UpdateConfig.MaxFailureRatio
260 260
 }
261 261
 
262
+func (ctx *serviceInspectContext) HasRollbackConfig() bool {
263
+	return ctx.Service.Spec.RollbackConfig != nil
264
+}
265
+
266
+func (ctx *serviceInspectContext) RollbackParallelism() uint64 {
267
+	return ctx.Service.Spec.RollbackConfig.Parallelism
268
+}
269
+
270
+func (ctx *serviceInspectContext) HasRollbackDelay() bool {
271
+	return ctx.Service.Spec.RollbackConfig.Delay.Nanoseconds() > 0
272
+}
273
+
274
+func (ctx *serviceInspectContext) RollbackDelay() time.Duration {
275
+	return ctx.Service.Spec.RollbackConfig.Delay
276
+}
277
+
278
+func (ctx *serviceInspectContext) RollbackOnFailure() string {
279
+	return ctx.Service.Spec.RollbackConfig.FailureAction
280
+}
281
+
282
+func (ctx *serviceInspectContext) HasRollbackMonitor() bool {
283
+	return ctx.Service.Spec.RollbackConfig.Monitor.Nanoseconds() > 0
284
+}
285
+
286
+func (ctx *serviceInspectContext) RollbackMonitor() time.Duration {
287
+	return ctx.Service.Spec.RollbackConfig.Monitor
288
+}
289
+
290
+func (ctx *serviceInspectContext) RollbackMaxFailureRatio() float32 {
291
+	return ctx.Service.Spec.RollbackConfig.MaxFailureRatio
292
+}
293
+
262 294
 func (ctx *serviceInspectContext) ContainerImage() string {
263 295
 	return ctx.Service.Spec.TaskTemplate.ContainerSpec.Image
264 296
 }
... ...
@@ -49,7 +49,6 @@ func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time)
49 49
 					Replicas: &two,
50 50
 				},
51 51
 			},
52
-			UpdateConfig: nil,
53 52
 			Networks: []swarm.NetworkAttachmentConfig{
54 53
 				{
55 54
 					Target:  "5vpyomhb6ievnk0i0o60gcnei",
... ...
@@ -165,6 +165,16 @@ type updateOptions struct {
165 165
 	maxFailureRatio floatValue
166 166
 }
167 167
 
168
+func (opts updateOptions) config() *swarm.UpdateConfig {
169
+	return &swarm.UpdateConfig{
170
+		Parallelism:     opts.parallelism,
171
+		Delay:           opts.delay,
172
+		Monitor:         opts.monitor,
173
+		FailureAction:   opts.onFailure,
174
+		MaxFailureRatio: opts.maxFailureRatio.Value(),
175
+	}
176
+}
177
+
168 178
 type resourceOptions struct {
169 179
 	limitCPU      opts.NanoCPUs
170 180
 	limitMemBytes opts.MemBytes
... ...
@@ -328,6 +338,7 @@ type serviceOptions struct {
328 328
 	constraints    opts.ListOpts
329 329
 	placementPrefs placementPrefOpts
330 330
 	update         updateOptions
331
+	rollback       updateOptions
331 332
 	networks       opts.ListOpts
332 333
 	endpoint       endpointOptions
333 334
 
... ...
@@ -445,16 +456,11 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
445 445
 			},
446 446
 			LogDriver: opts.logDriver.toLogDriver(),
447 447
 		},
448
-		Networks: convertNetworks(opts.networks.GetAll()),
449
-		Mode:     serviceMode,
450
-		UpdateConfig: &swarm.UpdateConfig{
451
-			Parallelism:     opts.update.parallelism,
452
-			Delay:           opts.update.delay,
453
-			Monitor:         opts.update.monitor,
454
-			FailureAction:   opts.update.onFailure,
455
-			MaxFailureRatio: opts.update.maxFailureRatio.Value(),
456
-		},
457
-		EndpointSpec: opts.endpoint.ToEndpointSpec(),
448
+		Networks:       convertNetworks(opts.networks.GetAll()),
449
+		Mode:           serviceMode,
450
+		UpdateConfig:   opts.update.config(),
451
+		RollbackConfig: opts.rollback.config(),
452
+		EndpointSpec:   opts.endpoint.ToEndpointSpec(),
458 453
 	}
459 454
 
460 455
 	return service, nil
... ...
@@ -491,6 +497,17 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
491 491
 	flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update")
492 492
 	flags.SetAnnotation(flagUpdateMaxFailureRatio, "version", []string{"1.25"})
493 493
 
494
+	flags.Uint64Var(&opts.rollback.parallelism, flagRollbackParallelism, 1, "Maximum number of tasks rolled back simultaneously (0 to roll back all at once)")
495
+	flags.SetAnnotation(flagRollbackParallelism, "version", []string{"1.27"})
496
+	flags.DurationVar(&opts.rollback.delay, flagRollbackDelay, time.Duration(0), "Delay between task rollbacks (ns|us|ms|s|m|h) (default 0s)")
497
+	flags.SetAnnotation(flagRollbackDelay, "version", []string{"1.27"})
498
+	flags.DurationVar(&opts.rollback.monitor, flagRollbackMonitor, time.Duration(0), "Duration after each task rollback to monitor for failure (ns|us|ms|s|m|h) (default 0s)")
499
+	flags.SetAnnotation(flagRollbackMonitor, "version", []string{"1.27"})
500
+	flags.StringVar(&opts.rollback.onFailure, flagRollbackFailureAction, "pause", `Action on rollback failure ("pause"|"continue")`)
501
+	flags.SetAnnotation(flagRollbackFailureAction, "version", []string{"1.27"})
502
+	flags.Var(&opts.rollback.maxFailureRatio, flagRollbackMaxFailureRatio, "Failure rate to tolerate during a rollback")
503
+	flags.SetAnnotation(flagRollbackMaxFailureRatio, "version", []string{"1.27"})
504
+
494 505
 	flags.StringVar(&opts.endpoint.mode, flagEndpointMode, "vip", "Endpoint mode (vip or dnsrr)")
495 506
 
496 507
 	flags.BoolVar(&opts.registryAuth, flagRegistryAuth, false, "Send registry authentication details to swarm agents")
... ...
@@ -520,77 +537,82 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
520 520
 }
521 521
 
522 522
 const (
523
-	flagPlacementPref         = "placement-pref"
524
-	flagPlacementPrefAdd      = "placement-pref-add"
525
-	flagPlacementPrefRemove   = "placement-pref-rm"
526
-	flagConstraint            = "constraint"
527
-	flagConstraintRemove      = "constraint-rm"
528
-	flagConstraintAdd         = "constraint-add"
529
-	flagContainerLabel        = "container-label"
530
-	flagContainerLabelRemove  = "container-label-rm"
531
-	flagContainerLabelAdd     = "container-label-add"
532
-	flagDNS                   = "dns"
533
-	flagDNSRemove             = "dns-rm"
534
-	flagDNSAdd                = "dns-add"
535
-	flagDNSOption             = "dns-option"
536
-	flagDNSOptionRemove       = "dns-option-rm"
537
-	flagDNSOptionAdd          = "dns-option-add"
538
-	flagDNSSearch             = "dns-search"
539
-	flagDNSSearchRemove       = "dns-search-rm"
540
-	flagDNSSearchAdd          = "dns-search-add"
541
-	flagEndpointMode          = "endpoint-mode"
542
-	flagHost                  = "host"
543
-	flagHostAdd               = "host-add"
544
-	flagHostRemove            = "host-rm"
545
-	flagHostname              = "hostname"
546
-	flagEnv                   = "env"
547
-	flagEnvFile               = "env-file"
548
-	flagEnvRemove             = "env-rm"
549
-	flagEnvAdd                = "env-add"
550
-	flagGroup                 = "group"
551
-	flagGroupAdd              = "group-add"
552
-	flagGroupRemove           = "group-rm"
553
-	flagLabel                 = "label"
554
-	flagLabelRemove           = "label-rm"
555
-	flagLabelAdd              = "label-add"
556
-	flagLimitCPU              = "limit-cpu"
557
-	flagLimitMemory           = "limit-memory"
558
-	flagMode                  = "mode"
559
-	flagMount                 = "mount"
560
-	flagMountRemove           = "mount-rm"
561
-	flagMountAdd              = "mount-add"
562
-	flagName                  = "name"
563
-	flagNetwork               = "network"
564
-	flagPublish               = "publish"
565
-	flagPublishRemove         = "publish-rm"
566
-	flagPublishAdd            = "publish-add"
567
-	flagReadOnly              = "read-only"
568
-	flagReplicas              = "replicas"
569
-	flagReserveCPU            = "reserve-cpu"
570
-	flagReserveMemory         = "reserve-memory"
571
-	flagRestartCondition      = "restart-condition"
572
-	flagRestartDelay          = "restart-delay"
573
-	flagRestartMaxAttempts    = "restart-max-attempts"
574
-	flagRestartWindow         = "restart-window"
575
-	flagStopGracePeriod       = "stop-grace-period"
576
-	flagStopSignal            = "stop-signal"
577
-	flagTTY                   = "tty"
578
-	flagUpdateDelay           = "update-delay"
579
-	flagUpdateFailureAction   = "update-failure-action"
580
-	flagUpdateMaxFailureRatio = "update-max-failure-ratio"
581
-	flagUpdateMonitor         = "update-monitor"
582
-	flagUpdateParallelism     = "update-parallelism"
583
-	flagUser                  = "user"
584
-	flagWorkdir               = "workdir"
585
-	flagRegistryAuth          = "with-registry-auth"
586
-	flagLogDriver             = "log-driver"
587
-	flagLogOpt                = "log-opt"
588
-	flagHealthCmd             = "health-cmd"
589
-	flagHealthInterval        = "health-interval"
590
-	flagHealthRetries         = "health-retries"
591
-	flagHealthTimeout         = "health-timeout"
592
-	flagNoHealthcheck         = "no-healthcheck"
593
-	flagSecret                = "secret"
594
-	flagSecretAdd             = "secret-add"
595
-	flagSecretRemove          = "secret-rm"
523
+	flagPlacementPref           = "placement-pref"
524
+	flagPlacementPrefAdd        = "placement-pref-add"
525
+	flagPlacementPrefRemove     = "placement-pref-rm"
526
+	flagConstraint              = "constraint"
527
+	flagConstraintRemove        = "constraint-rm"
528
+	flagConstraintAdd           = "constraint-add"
529
+	flagContainerLabel          = "container-label"
530
+	flagContainerLabelRemove    = "container-label-rm"
531
+	flagContainerLabelAdd       = "container-label-add"
532
+	flagDNS                     = "dns"
533
+	flagDNSRemove               = "dns-rm"
534
+	flagDNSAdd                  = "dns-add"
535
+	flagDNSOption               = "dns-option"
536
+	flagDNSOptionRemove         = "dns-option-rm"
537
+	flagDNSOptionAdd            = "dns-option-add"
538
+	flagDNSSearch               = "dns-search"
539
+	flagDNSSearchRemove         = "dns-search-rm"
540
+	flagDNSSearchAdd            = "dns-search-add"
541
+	flagEndpointMode            = "endpoint-mode"
542
+	flagHost                    = "host"
543
+	flagHostAdd                 = "host-add"
544
+	flagHostRemove              = "host-rm"
545
+	flagHostname                = "hostname"
546
+	flagEnv                     = "env"
547
+	flagEnvFile                 = "env-file"
548
+	flagEnvRemove               = "env-rm"
549
+	flagEnvAdd                  = "env-add"
550
+	flagGroup                   = "group"
551
+	flagGroupAdd                = "group-add"
552
+	flagGroupRemove             = "group-rm"
553
+	flagLabel                   = "label"
554
+	flagLabelRemove             = "label-rm"
555
+	flagLabelAdd                = "label-add"
556
+	flagLimitCPU                = "limit-cpu"
557
+	flagLimitMemory             = "limit-memory"
558
+	flagMode                    = "mode"
559
+	flagMount                   = "mount"
560
+	flagMountRemove             = "mount-rm"
561
+	flagMountAdd                = "mount-add"
562
+	flagName                    = "name"
563
+	flagNetwork                 = "network"
564
+	flagPublish                 = "publish"
565
+	flagPublishRemove           = "publish-rm"
566
+	flagPublishAdd              = "publish-add"
567
+	flagReadOnly                = "read-only"
568
+	flagReplicas                = "replicas"
569
+	flagReserveCPU              = "reserve-cpu"
570
+	flagReserveMemory           = "reserve-memory"
571
+	flagRestartCondition        = "restart-condition"
572
+	flagRestartDelay            = "restart-delay"
573
+	flagRestartMaxAttempts      = "restart-max-attempts"
574
+	flagRestartWindow           = "restart-window"
575
+	flagRollbackDelay           = "rollback-delay"
576
+	flagRollbackFailureAction   = "rollback-failure-action"
577
+	flagRollbackMaxFailureRatio = "rollback-max-failure-ratio"
578
+	flagRollbackMonitor         = "rollback-monitor"
579
+	flagRollbackParallelism     = "rollback-parallelism"
580
+	flagStopGracePeriod         = "stop-grace-period"
581
+	flagStopSignal              = "stop-signal"
582
+	flagTTY                     = "tty"
583
+	flagUpdateDelay             = "update-delay"
584
+	flagUpdateFailureAction     = "update-failure-action"
585
+	flagUpdateMaxFailureRatio   = "update-max-failure-ratio"
586
+	flagUpdateMonitor           = "update-monitor"
587
+	flagUpdateParallelism       = "update-parallelism"
588
+	flagUser                    = "user"
589
+	flagWorkdir                 = "workdir"
590
+	flagRegistryAuth            = "with-registry-auth"
591
+	flagLogDriver               = "log-driver"
592
+	flagLogOpt                  = "log-opt"
593
+	flagHealthCmd               = "health-cmd"
594
+	flagHealthInterval          = "health-interval"
595
+	flagHealthRetries           = "health-retries"
596
+	flagHealthTimeout           = "health-timeout"
597
+	flagNoHealthcheck           = "no-healthcheck"
598
+	flagSecret                  = "secret"
599
+	flagSecretAdd               = "secret-add"
600
+	flagSecretRemove            = "secret-rm"
596 601
 )
... ...
@@ -289,6 +289,17 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
289 289
 		updateFloatValue(flagUpdateMaxFailureRatio, &spec.UpdateConfig.MaxFailureRatio)
290 290
 	}
291 291
 
292
+	if anyChanged(flags, flagRollbackParallelism, flagRollbackDelay, flagRollbackMonitor, flagRollbackFailureAction, flagRollbackMaxFailureRatio) {
293
+		if spec.RollbackConfig == nil {
294
+			spec.RollbackConfig = &swarm.UpdateConfig{}
295
+		}
296
+		updateUint64(flagRollbackParallelism, &spec.RollbackConfig.Parallelism)
297
+		updateDuration(flagRollbackDelay, &spec.RollbackConfig.Delay)
298
+		updateDuration(flagRollbackMonitor, &spec.RollbackConfig.Monitor)
299
+		updateString(flagRollbackFailureAction, &spec.RollbackConfig.FailureAction)
300
+		updateFloatValue(flagRollbackMaxFailureRatio, &spec.RollbackConfig.MaxFailureRatio)
301
+	}
302
+
292 303
 	if flags.Changed(flagEndpointMode) {
293 304
 		value, _ := flags.GetString(flagEndpointMode)
294 305
 		if spec.EndpointSpec == nil {
... ...
@@ -92,26 +92,8 @@ func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) *types.ServiceSpec {
92 92
 	}
93 93
 
94 94
 	// UpdateConfig
95
-	if spec.Update != nil {
96
-		convertedSpec.UpdateConfig = &types.UpdateConfig{
97
-			Parallelism:     spec.Update.Parallelism,
98
-			MaxFailureRatio: spec.Update.MaxFailureRatio,
99
-		}
100
-
101
-		convertedSpec.UpdateConfig.Delay = spec.Update.Delay
102
-		if spec.Update.Monitor != nil {
103
-			convertedSpec.UpdateConfig.Monitor, _ = gogotypes.DurationFromProto(spec.Update.Monitor)
104
-		}
105
-
106
-		switch spec.Update.FailureAction {
107
-		case swarmapi.UpdateConfig_PAUSE:
108
-			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionPause
109
-		case swarmapi.UpdateConfig_CONTINUE:
110
-			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionContinue
111
-		case swarmapi.UpdateConfig_ROLLBACK:
112
-			convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionRollback
113
-		}
114
-	}
95
+	convertedSpec.UpdateConfig = updateConfigFromGRPC(spec.Update)
96
+	convertedSpec.RollbackConfig = updateConfigFromGRPC(spec.Rollback)
115 97
 
116 98
 	// Mode
117 99
 	switch t := spec.GetMode().(type) {
... ...
@@ -188,27 +170,13 @@ func ServiceSpecToGRPC(s types.ServiceSpec) (swarmapi.ServiceSpec, error) {
188 188
 		}
189 189
 	}
190 190
 
191
-	if s.UpdateConfig != nil {
192
-		var failureAction swarmapi.UpdateConfig_FailureAction
193
-		switch s.UpdateConfig.FailureAction {
194
-		case types.UpdateFailureActionPause, "":
195
-			failureAction = swarmapi.UpdateConfig_PAUSE
196
-		case types.UpdateFailureActionContinue:
197
-			failureAction = swarmapi.UpdateConfig_CONTINUE
198
-		case types.UpdateFailureActionRollback:
199
-			failureAction = swarmapi.UpdateConfig_ROLLBACK
200
-		default:
201
-			return swarmapi.ServiceSpec{}, fmt.Errorf("unrecognized update failure action %s", s.UpdateConfig.FailureAction)
202
-		}
203
-		spec.Update = &swarmapi.UpdateConfig{
204
-			Parallelism:     s.UpdateConfig.Parallelism,
205
-			Delay:           s.UpdateConfig.Delay,
206
-			FailureAction:   failureAction,
207
-			MaxFailureRatio: s.UpdateConfig.MaxFailureRatio,
208
-		}
209
-		if s.UpdateConfig.Monitor != 0 {
210
-			spec.Update.Monitor = gogotypes.DurationProto(s.UpdateConfig.Monitor)
211
-		}
191
+	spec.Update, err = updateConfigToGRPC(s.UpdateConfig)
192
+	if err != nil {
193
+		return swarmapi.ServiceSpec{}, err
194
+	}
195
+	spec.Rollback, err = updateConfigToGRPC(s.RollbackConfig)
196
+	if err != nil {
197
+		return swarmapi.Servicepec{}, err
212 198
 	}
213 199
 
214 200
 	if s.EndpointSpec != nil {
... ...
@@ -415,3 +383,58 @@ func driverToGRPC(p *types.Driver) *swarmapi.Driver {
415 415
 		Options: p.Options,
416 416
 	}
417 417
 }
418
+
419
+func updateConfigFromGRPC(updateConfig *swarmapi.UpdateConfig) *types.UpdateConfig {
420
+	if updateConfig == nil {
421
+		return nil
422
+	}
423
+
424
+	converted := &types.UpdateConfig{
425
+		Parallelism:     updateConfig.Parallelism,
426
+		MaxFailureRatio: updateConfig.MaxFailureRatio,
427
+	}
428
+
429
+	converted.Delay = updateConfig.Delay
430
+	if updateConfig.Monitor != nil {
431
+		converted.Monitor, _ = gogotypes.DurationFromProto(updateConfig.Monitor)
432
+	}
433
+
434
+	switch updateConfig.FailureAction {
435
+	case swarmapi.UpdateConfig_PAUSE:
436
+		converted.FailureAction = types.UpdateFailureActionPause
437
+	case swarmapi.UpdateConfig_CONTINUE:
438
+		converted.FailureAction = types.UpdateFailureActionContinue
439
+	case swarmapi.UpdateConfig_ROLLBACK:
440
+		converted.FailureAction = types.UpdateFailureActionRollback
441
+	}
442
+
443
+	return converted
444
+}
445
+
446
+func updateConfigToGRPC(updateConfig *types.UpdateConfig) (*swarmapi.UpdateConfig, error) {
447
+	if updateConfig == nil {
448
+		return nil, nil
449
+	}
450
+
451
+	converted := &swarmapi.UpdateConfig{
452
+		Parallelism:     updateConfig.Parallelism,
453
+		Delay:           updateConfig.Delay,
454
+		MaxFailureRatio: updateConfig.MaxFailureRatio,
455
+	}
456
+
457
+	switch updateConfig.FailureAction {
458
+	case types.UpdateFailureActionPause, "":
459
+		converted.FailureAction = swarmapi.UpdateConfig_PAUSE
460
+	case types.UpdateFailureActionContinue:
461
+		converted.FailureAction = swarmapi.UpdateConfig_CONTINUE
462
+	case types.UpdateFailureActionRollback:
463
+		converted.FailureAction = swarmapi.UpdateConfig_ROLLBACK
464
+	default:
465
+		return nil, fmt.Errorf("unrecongized update failure action %s", updateConfig.FailureAction)
466
+	}
467
+	if updateConfig.Monitor != 0 {
468
+		converted.Monitor = gogotypes.DurationProto(updateConfig.Monitor)
469
+	}
470
+
471
+	return converted, nil
472
+}
... ...
@@ -23,6 +23,7 @@ keywords: "API, Docker, rcli, REST, documentation"
23 23
 * `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.
24 24
 * `POST /build` now accepts `extrahosts` parameter to specify a host to ip mapping to use during the build.
25 25
 * `POST /services/create` and `POST /services/(id or name)/update` now accept a `rollback` value for `FailureAction`.
26
+* `POST /services/create` and `POST /services/(id or name)/update` now accept an optional `RollbackConfig` object which specifies rollback options.
26 27
 
27 28
 ## v1.26 API changes
28 29
 
... ...
@@ -21,54 +21,61 @@ Usage:  docker service create [OPTIONS] IMAGE [COMMAND] [ARG...]
21 21
 Create a new service
22 22
 
23 23
 Options:
24
-      --constraint list                  Placement constraints (default [])
25
-      --container-label list             Container labels (default [])
26
-      --dns list                         Set custom DNS servers (default [])
27
-      --dns-option list                  Set DNS options (default [])
28
-      --dns-search list                  Set custom DNS search domains (default [])
29
-      --endpoint-mode string             Endpoint mode ("vip"|"dnsrr") (default "vip")
30
-  -e, --env list                         Set environment variables (default [])
31
-      --env-file list                    Read in a file of environment variables (default [])
32
-      --group list                       Set one or more supplementary user groups for the container (default [])
33
-      --health-cmd string                Command to run to check health
34
-      --health-interval duration         Time between running the check (ns|us|ms|s|m|h)
35
-      --health-retries int               Consecutive failures needed to report unhealthy
36
-      --health-timeout duration          Maximum time to allow one check to run (ns|us|ms|s|m|h)
37
-      --help                             Print usage
38
-      --host list                        Set one or more custom host-to-IP mappings (host:ip) (default [])
39
-      --hostname string                  Container hostname
40
-  -l, --label list                       Service labels (default [])
41
-      --limit-cpu decimal                Limit CPUs (default 0.000)
42
-      --limit-memory bytes               Limit Memory
43
-      --log-driver string                Logging driver for service
44
-      --log-opt list                     Logging driver options (default [])
45
-      --mode string                      Service mode (replicated or global) (default "replicated")
46
-      --mount mount                      Attach a filesystem mount to the service
47
-      --name string                      Service name
48
-      --network list                     Network attachments (default [])
49
-      --no-healthcheck                   Disable any container-specified HEALTHCHECK
50
-      --placement-pref pref              Add a placement preference
51
-  -p, --publish port                     Publish a port as a node port
52
-      --read-only                        Mount the container's root filesystem as read only
53
-      --replicas uint                    Number of tasks
54
-      --reserve-cpu decimal              Reserve CPUs (default 0.000)
55
-      --reserve-memory bytes             Reserve Memory
56
-      --restart-condition string         Restart when condition is met ("none"|"on-failure"|"any")
57
-      --restart-delay duration           Delay between restart attempts (ns|us|ms|s|m|h)
58
-      --restart-max-attempts uint        Maximum number of restarts before giving up
59
-      --restart-window duration          Window used to evaluate the restart policy (ns|us|ms|s|m|h)
60
-      --secret secret                    Specify secrets to expose to the service
61
-      --stop-grace-period duration       Time to wait before force killing a container (ns|us|ms|s|m|h)
62
-      --stop-signal string               Signal to stop the container
63
-  -t, --tty                              Allocate a pseudo-TTY
64
-      --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
65
-      --update-failure-action string     Action on update failure ("pause"|"continue"|"rollback") (default "pause")
66
-      --update-max-failure-ratio float   Failure rate to tolerate during an update
67
-      --update-monitor duration          Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
68
-      --update-parallelism uint          Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)
69
-  -u, --user string                      Username or UID (format: <name|uid>[:<group|gid>])
70
-      --with-registry-auth               Send registry authentication details to swarm agents
71
-  -w, --workdir string                   Working directory inside the container
24
+      --constraint list                    Placement constraints (default [])
25
+      --container-label list               Container labels (default [])
26
+      --dns list                           Set custom DNS servers (default [])
27
+      --dns-option list                    Set DNS options (default [])
28
+      --dns-search list                    Set custom DNS search domains (default [])
29
+      --endpoint-mode string               Endpoint mode ("vip"|"dnsrr") (default "vip")
30
+  -e, --env list                           Set environment variables (default [])
31
+      --env-file list                      Read in a file of environment variables (default [])
32
+      --group list                         Set one or more supplementary user groups for the container (default [])
33
+      --health-cmd string                  Command to run to check health
34
+      --health-interval duration           Time between running the check (ns|us|ms|s|m|h)
35
+      --health-retries int                 Consecutive failures needed to report unhealthy
36
+      --health-timeout duration            Maximum time to allow one check to run (ns|us|ms|s|m|h)
37
+      --help                               Print usage
38
+      --host list                          Set one or more custom host-to-IP mappings (host:ip) (default [])
39
+      --hostname string                    Container hostname
40
+  -l, --label list                         Service labels (default [])
41
+      --limit-cpu decimal                  Limit CPUs (default 0.000)
42
+      --limit-memory bytes                 Limit Memory
43
+      --log-driver string                  Logging driver for service
44
+      --log-opt list                       Logging driver options (default [])
45
+      --mode string                        Service mode (replicated or global) (default "replicated")
46
+      --mount mount                        Attach a filesystem mount to the service
47
+      --name string                        Service name
48
+      --network list                       Network attachments (default [])
49
+      --no-healthcheck                     Disable any container-specified HEALTHCHECK
50
+      --placement-pref pref                Add a placement preference
51
+  -p, --publish port                       Publish a port as a node port
52
+      --read-only                          Mount the container's root filesystem as read only
53
+      --replicas uint                      Number of tasks
54
+      --reserve-cpu decimal                Reserve CPUs (default 0.000)
55
+      --reserve-memory bytes               Reserve Memory
56
+      --restart-condition string           Restart when condition is met ("none"|"on-failure"|"any")
57
+      --restart-delay duration             Delay between restart attempts (ns|us|ms|s|m|h)
58
+      --restart-max-attempts uint          Maximum number of restarts before giving up
59
+      --restart-window duration            Window used to evaluate the restart policy (ns|us|ms|s|m|h)
60
+      --rollback-delay duration            Delay between task rollbacks (ns|us|ms|s|m|h) (default 0s)
61
+      --rollback-failure-action string     Action on rollback failure ("pause"|"continue") (default "pause")
62
+      --rollback-max-failure-ratio float   Failure rate to tolerate during a rollback
63
+      --rollback-monitor duration          Duration after each task rollback to monitor for failure
64
+                                           (ns|us|ms|s|m|h) (default 0s)
65
+      --rollback-parallelism uint          Maximum number of tasks rolled back simultaneously (0 to roll
66
+                                           back all at once) (default 1)
67
+      --secret secret                      Specify secrets to expose to the service
68
+      --stop-grace-period duration         Time to wait before force killing a container (ns|us|ms|s|m|h)
69
+      --stop-signal string                 Signal to stop the container
70
+  -t, --tty                                Allocate a pseudo-TTY
71
+      --update-delay duration              Delay between updates (ns|us|ms|s|m|h) (default 0s)
72
+      --update-failure-action string       Action on update failure ("pause"|"continue"|"rollback") (default "pause")
73
+      --update-max-failure-ratio float     Failure rate to tolerate during an update
74
+      --update-monitor duration            Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
75
+      --update-parallelism uint            Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)
76
+  -u, --user string                        Username or UID (format: <name|uid>[:<group|gid>])
77
+      --with-registry-auth                 Send registry authentication details to swarm agents
78
+  -w, --workdir string                     Working directory inside the container
72 79
 ```
73 80
 
74 81
 ## Description
... ...
@@ -21,67 +21,74 @@ Usage:  docker service update [OPTIONS] SERVICE
21 21
 Update a service
22 22
 
23 23
 Options:
24
-      --args string                      Service command args
25
-      --constraint-add list              Add or update a placement constraint (default [])
26
-      --constraint-rm list               Remove a constraint (default [])
27
-      --container-label-add list         Add or update a container label (default [])
28
-      --container-label-rm list          Remove a container label by its key (default [])
29
-      --dns-add list                     Add or update a custom DNS server (default [])
30
-      --dns-option-add list              Add or update a DNS option (default [])
31
-      --dns-option-rm list               Remove a DNS option (default [])
32
-      --dns-rm list                      Remove a custom DNS server (default [])
33
-      --dns-search-add list              Add or update a custom DNS search domain (default [])
34
-      --dns-search-rm list               Remove a DNS search domain (default [])
35
-      --endpoint-mode string             Endpoint mode ("vip"|"dnsrr") (default "vip")
36
-      --env-add list                     Add or update an environment variable (default [])
37
-      --env-rm list                      Remove an environment variable (default [])
38
-      --force                            Force update even if no changes require it
39
-      --group-add list                   Add an additional supplementary user group to the container (default [])
40
-      --group-rm list                    Remove a previously added supplementary user group from the container (default [])
41
-      --health-cmd string                Command to run to check health
42
-      --health-interval duration         Time between running the check (ns|us|ms|s|m|h)
43
-      --health-retries int               Consecutive failures needed to report unhealthy
44
-      --health-timeout duration          Maximum time to allow one check to run (ns|us|ms|s|m|h)
45
-      --help                             Print usage
46
-      --host-add list                    Add or update a custom host-to-IP mapping (host:ip) (default [])
47
-      --host-rm list                     Remove a custom host-to-IP mapping (host:ip) (default [])
48
-      --hostname string                  Container hostname
49
-      --image string                     Service image tag
50
-      --label-add list                   Add or update a service label (default [])
51
-      --label-rm list                    Remove a label by its key (default [])
52
-      --limit-cpu decimal                Limit CPUs (default 0.000)
53
-      --limit-memory bytes               Limit Memory
54
-      --log-driver string                Logging driver for service
55
-      --log-opt list                     Logging driver options (default [])
56
-      --mount-add mount                  Add or update a mount on a service
57
-      --mount-rm list                    Remove a mount by its target path (default [])
58
-      --no-healthcheck                   Disable any container-specified HEALTHCHECK
59
-      --placement-pref-add pref          Add a placement preference
60
-      --placement-pref-rm pref           Remove a placement preference
61
-      --publish-add port                 Add or update a published port
62
-      --publish-rm port                  Remove a published port by its target port
63
-      --read-only                        Mount the container's root filesystem as read only
64
-      --replicas uint                    Number of tasks
65
-      --reserve-cpu decimal              Reserve CPUs (default 0.000)
66
-      --reserve-memory bytes             Reserve Memory
67
-      --restart-condition string         Restart when condition is met ("none"|"on-failure"|"any")
68
-      --restart-delay duration           Delay between restart attempts (ns|us|ms|s|m|h)
69
-      --restart-max-attempts uint        Maximum number of restarts before giving up
70
-      --restart-window duration          Window used to evaluate the restart policy (ns|us|ms|s|m|h)
71
-      --rollback                         Rollback to previous specification
72
-      --secret-add secret                Add or update a secret on a service
73
-      --secret-rm list                   Remove a secret (default [])
74
-      --stop-grace-period duration       Time to wait before force killing a container (ns|us|ms|s|m|h)
75
-      --stop-signal string               Signal to stop the container
76
-  -t, --tty                              Allocate a pseudo-TTY
77
-      --update-delay duration            Delay between updates (ns|us|ms|s|m|h) (default 0s)
78
-      --update-failure-action string     Action on update failure ("pause"|"continue"|"rollback") (default "pause")
79
-      --update-max-failure-ratio float   Failure rate to tolerate during an update
80
-      --update-monitor duration          Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
81
-      --update-parallelism uint          Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)
82
-  -u, --user string                      Username or UID (format: <name|uid>[:<group|gid>])
83
-      --with-registry-auth               Send registry authentication details to swarm agents
84
-  -w, --workdir string                   Working directory inside the container
24
+      --args string                        Service command args
25
+      --constraint-add list                Add or update a placement constraint (default [])
26
+      --constraint-rm list                 Remove a constraint (default [])
27
+      --container-label-add list           Add or update a container label (default [])
28
+      --container-label-rm list            Remove a container label by its key (default [])
29
+      --dns-add list                       Add or update a custom DNS server (default [])
30
+      --dns-option-add list                Add or update a DNS option (default [])
31
+      --dns-option-rm list                 Remove a DNS option (default [])
32
+      --dns-rm list                        Remove a custom DNS server (default [])
33
+      --dns-search-add list                Add or update a custom DNS search domain (default [])
34
+      --dns-search-rm list                 Remove a DNS search domain (default [])
35
+      --endpoint-mode string               Endpoint mode ("vip"|"dnsrr") (default "vip")
36
+      --env-add list                       Add or update an environment variable (default [])
37
+      --env-rm list                        Remove an environment variable (default [])
38
+      --force                              Force update even if no changes require it
39
+      --group-add list                     Add an additional supplementary user group to the container (default [])
40
+      --group-rm list                      Remove a previously added supplementary user group from the container (default [])
41
+      --health-cmd string                  Command to run to check health
42
+      --health-interval duration           Time between running the check (ns|us|ms|s|m|h)
43
+      --health-retries int                 Consecutive failures needed to report unhealthy
44
+      --health-timeout duration            Maximum time to allow one check to run (ns|us|ms|s|m|h)
45
+      --help                               Print usage
46
+      --host-add list                      Add or update a custom host-to-IP mapping (host:ip) (default [])
47
+      --host-rm list                       Remove a custom host-to-IP mapping (host:ip) (default [])
48
+      --hostname string                    Container hostname
49
+      --image string                       Service image tag
50
+      --label-add list                     Add or update a service label (default [])
51
+      --label-rm list                      Remove a label by its key (default [])
52
+      --limit-cpu decimal                  Limit CPUs (default 0.000)
53
+      --limit-memory bytes                 Limit Memory
54
+      --log-driver string                  Logging driver for service
55
+      --log-opt list                       Logging driver options (default [])
56
+      --mount-add mount                    Add or update a mount on a service
57
+      --mount-rm list                      Remove a mount by its target path (default [])
58
+      --no-healthcheck                     Disable any container-specified HEALTHCHECK
59
+      --placement-pref-add pref            Add a placement preference
60
+      --placement-pref-rm pref             Remove a placement preference
61
+      --publish-add port                   Add or update a published port
62
+      --publish-rm port                    Remove a published port by its target port
63
+      --read-only                          Mount the container's root filesystem as read only
64
+      --replicas uint                      Number of tasks
65
+      --reserve-cpu decimal                Reserve CPUs (default 0.000)
66
+      --reserve-memory bytes               Reserve Memory
67
+      --restart-condition string           Restart when condition is met ("none"|"on-failure"|"any")
68
+      --restart-delay duration             Delay between restart attempts (ns|us|ms|s|m|h)
69
+      --restart-max-attempts uint          Maximum number of restarts before giving up
70
+      --restart-window duration            Window used to evaluate the restart policy (ns|us|ms|s|m|h)
71
+      --rollback                           Rollback to previous specification
72
+      --rollback-delay duration            Delay between task rollbacks (ns|us|ms|s|m|h) (default 0s)
73
+      --rollback-failure-action string     Action on rollback failure ("pause"|"continue") (default "pause")
74
+      --rollback-max-failure-ratio float   Failure rate to tolerate during a rollback
75
+      --rollback-monitor duration          Duration after each task rollback to monitor for failure
76
+                                           (ns|us|ms|s|m|h) (default 0s)
77
+      --rollback-parallelism uint          Maximum number of tasks rolled back simultaneously (0 to roll
78
+                                           back all at once) (default 1)
79
+      --secret-add secret                  Add or update a secret on a service
80
+      --secret-rm list                     Remove a secret (default [])
81
+      --stop-grace-period duration         Time to wait before force killing a container (ns|us|ms|s|m|h)
82
+      --stop-signal string                 Signal to stop the container
83
+  -t, --tty                                Allocate a pseudo-TTY
84
+      --update-delay duration              Delay between updates (ns|us|ms|s|m|h) (default 0s)
85
+      --update-failure-action string       Action on update failure ("pause"|"continue"|"rollback") (default "pause")
86
+      --update-max-failure-ratio float     Failure rate to tolerate during an update
87
+      --update-monitor duration            Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)
88
+      --update-parallelism uint            Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)
89
+  -u, --user string                        Username or UID (format: <name|uid>[:<group|gid>])
90
+      --with-registry-auth                 Send registry authentication details to swarm agents
91
+  -w, --workdir string                     Working directory inside the container
85 92
 ```
86 93
 
87 94
 ## Description
... ...
@@ -202,6 +209,26 @@ web
202 202
 
203 203
 ```
204 204
 
205
+Services can also be set up to roll back to the previous version automatically
206
+when an update fails. To set up a service for automatic rollback, use
207
+`--update-failure-action=rollback`. A rollback will be triggered if the fraction
208
+of the tasks which failed to update successfully exceeds the value given with
209
+`--update-max-failure-ratio`.
210
+
211
+The rate, parallelism, and other parameters of a rollback operation are
212
+determined by the values passed with the following flags:
213
+
214
+- `--rollback-delay`
215
+- `--rollback-failure-action`
216
+- `--rollback-max-failure-ratio`
217
+- `--rollback-monitor`
218
+- `--rollback-parallelism`
219
+
220
+For example, a service set up with `--update-parallelism 1 --rollback-parallelism 3`
221
+will update one task at a time during a normal update, but during a rollback, 3
222
+tasks at a time will get rolled back. These rollback parameters are respected both
223
+during automatic rollbacks and for rollbacks initiated manually using `--rollback`.
224
+
205 225
 ### Add or remove secrets
206 226
 
207 227
 Use the `--secret-add` or `--secret-rm` options add or remove a service's