Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a88a24

Browse files
author
Aaron Lehmann
committed
Add support for rollback flags
Signed-off-by: Aaron Lehmann <[email protected]>
1 parent cc9d046 commit 3a88a24

10 files changed

Lines changed: 422 additions & 238 deletions

File tree

api/swagger.yaml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,32 @@ definitions:
22652265
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."
22662266
type: "number"
22672267
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
22682294
Networks:
22692295
description: "Array of network names or IDs to attach the service to."
22702296
type: "array"
@@ -2387,6 +2413,13 @@ definitions:
23872413
Replicas: 1
23882414
UpdateConfig:
23892415
Parallelism: 1
2416+
Delay: 1000000000
2417+
FailureAction: "pause"
2418+
Monitor: 15000000000
2419+
MaxFailureRatio: 0.15
2420+
RollbackConfig:
2421+
Parallelism: 1
2422+
Delay: 1000000000
23902423
FailureAction: "pause"
23912424
Monitor: 15000000000
23922425
MaxFailureRatio: 0.15
@@ -7436,9 +7469,17 @@ paths:
74367469
Replicated:
74377470
Replicas: 4
74387471
UpdateConfig:
7439-
Delay: 30000000000
74407472
Parallelism: 2
7473+
Delay: 1000000000
74417474
FailureAction: "pause"
7475+
Monitor: 15000000000
7476+
MaxFailureRatio: 0.15
7477+
RollbackConfig:
7478+
Parallelism: 1
7479+
Delay: 1000000000
7480+
FailureAction: "pause"
7481+
Monitor: 15000000000
7482+
MaxFailureRatio: 0.15
74427483
EndpointSpec:
74437484
Ports:
74447485
-
@@ -7564,7 +7605,15 @@ paths:
75647605
Replicated:
75657606
Replicas: 1
75667607
UpdateConfig:
7608+
Parallelism: 2
7609+
Delay: 1000000000
7610+
FailureAction: "pause"
7611+
Monitor: 15000000000
7612+
MaxFailureRatio: 0.15
7613+
RollbackConfig:
75677614
Parallelism: 1
7615+
Delay: 1000000000
7616+
FailureAction: "pause"
75687617
Monitor: 15000000000
75697618
MaxFailureRatio: 0.15
75707619
EndpointSpec:

api/types/swarm/service.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ type ServiceSpec struct {
1818

1919
// TaskTemplate defines how the service should construct new tasks when
2020
// 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"`
2425

2526
// Networks field in ServiceSpec is deprecated. The
2627
// same field in TaskSpec should be used instead.

cli/command/formatter/service.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ UpdateConfig:
5757
{{- end }}
5858
Max failure ratio: {{ .UpdateMaxFailureRatio }}
5959
{{- 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 }}
6072
ContainerSpec:
6173
Image: {{ .ContainerImage }}
6274
{{- if .ContainerArgs }}
@@ -259,6 +271,38 @@ func (ctx *serviceInspectContext) UpdateMaxFailureRatio() float32 {
259271
return ctx.Service.Spec.UpdateConfig.MaxFailureRatio
260272
}
261273

274+
func (ctx *serviceInspectContext) HasRollbackConfig() bool {
275+
return ctx.Service.Spec.RollbackConfig != nil
276+
}
277+
278+
func (ctx *serviceInspectContext) RollbackParallelism() uint64 {
279+
return ctx.Service.Spec.RollbackConfig.Parallelism
280+
}
281+
282+
func (ctx *serviceInspectContext) HasRollbackDelay() bool {
283+
return ctx.Service.Spec.RollbackConfig.Delay.Nanoseconds() > 0
284+
}
285+
286+
func (ctx *serviceInspectContext) RollbackDelay() time.Duration {
287+
return ctx.Service.Spec.RollbackConfig.Delay
288+
}
289+
290+
func (ctx *serviceInspectContext) RollbackOnFailure() string {
291+
return ctx.Service.Spec.RollbackConfig.FailureAction
292+
}
293+
294+
func (ctx *serviceInspectContext) HasRollbackMonitor() bool {
295+
return ctx.Service.Spec.RollbackConfig.Monitor.Nanoseconds() > 0
296+
}
297+
298+
func (ctx *serviceInspectContext) RollbackMonitor() time.Duration {
299+
return ctx.Service.Spec.RollbackConfig.Monitor
300+
}
301+
302+
func (ctx *serviceInspectContext) RollbackMaxFailureRatio() float32 {
303+
return ctx.Service.Spec.RollbackConfig.MaxFailureRatio
304+
}
305+
262306
func (ctx *serviceInspectContext) ContainerImage() string {
263307
return ctx.Service.Spec.TaskTemplate.ContainerSpec.Image
264308
}

cli/command/service/inspect_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time)
4949
Replicas: &two,
5050
},
5151
},
52-
UpdateConfig: nil,
5352
Networks: []swarm.NetworkAttachmentConfig{
5453
{
5554
Target: "5vpyomhb6ievnk0i0o60gcnei",

cli/command/service/opts.go

Lines changed: 105 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ type updateOptions struct {
165165
maxFailureRatio floatValue
166166
}
167167

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+
168178
type resourceOptions struct {
169179
limitCPU opts.NanoCPUs
170180
limitMemBytes opts.MemBytes
@@ -328,6 +338,7 @@ type serviceOptions struct {
328338
constraints opts.ListOpts
329339
placementPrefs placementPrefOpts
330340
update updateOptions
341+
rollback updateOptions
331342
networks opts.ListOpts
332343
endpoint endpointOptions
333344

@@ -445,16 +456,11 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
445456
},
446457
LogDriver: opts.logDriver.toLogDriver(),
447458
},
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(),
459+
Networks: convertNetworks(opts.networks.GetAll()),
460+
Mode: serviceMode,
461+
UpdateConfig: opts.update.config(),
462+
RollbackConfig: opts.rollback.config(),
463+
EndpointSpec: opts.endpoint.ToEndpointSpec(),
458464
}
459465

460466
return service, nil
@@ -491,6 +497,17 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
491497
flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update")
492498
flags.SetAnnotation(flagUpdateMaxFailureRatio, "version", []string{"1.25"})
493499

500+
flags.Uint64Var(&opts.rollback.parallelism, flagRollbackParallelism, 1, "Maximum number of tasks rolled back simultaneously (0 to roll back all at once)")
501+
flags.SetAnnotation(flagRollbackParallelism, "version", []string{"1.27"})
502+
flags.DurationVar(&opts.rollback.delay, flagRollbackDelay, time.Duration(0), "Delay between task rollbacks (ns|us|ms|s|m|h) (default 0s)")
503+
flags.SetAnnotation(flagRollbackDelay, "version", []string{"1.27"})
504+
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)")
505+
flags.SetAnnotation(flagRollbackMonitor, "version", []string{"1.27"})
506+
flags.StringVar(&opts.rollback.onFailure, flagRollbackFailureAction, "pause", `Action on rollback failure ("pause"|"continue")`)
507+
flags.SetAnnotation(flagRollbackFailureAction, "version", []string{"1.27"})
508+
flags.Var(&opts.rollback.maxFailureRatio, flagRollbackMaxFailureRatio, "Failure rate to tolerate during a rollback")
509+
flags.SetAnnotation(flagRollbackMaxFailureRatio, "version", []string{"1.27"})
510+
494511
flags.StringVar(&opts.endpoint.mode, flagEndpointMode, "vip", "Endpoint mode (vip or dnsrr)")
495512

496513
flags.BoolVar(&opts.registryAuth, flagRegistryAuth, false, "Send registry authentication details to swarm agents")
@@ -520,77 +537,82 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
520537
}
521538

522539
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"
540+
flagPlacementPref = "placement-pref"
541+
flagPlacementPrefAdd = "placement-pref-add"
542+
flagPlacementPrefRemove = "placement-pref-rm"
543+
flagConstraint = "constraint"
544+
flagConstraintRemove = "constraint-rm"
545+
flagConstraintAdd = "constraint-add"
546+
flagContainerLabel = "container-label"
547+
flagContainerLabelRemove = "container-label-rm"
548+
flagContainerLabelAdd = "container-label-add"
549+
flagDNS = "dns"
550+
flagDNSRemove = "dns-rm"
551+
flagDNSAdd = "dns-add"
552+
flagDNSOption = "dns-option"
553+
flagDNSOptionRemove = "dns-option-rm"
554+
flagDNSOptionAdd = "dns-option-add"
555+
flagDNSSearch = "dns-search"
556+
flagDNSSearchRemove = "dns-search-rm"
557+
flagDNSSearchAdd = "dns-search-add"
558+
flagEndpointMode = "endpoint-mode"
559+
flagHost = "host"
560+
flagHostAdd = "host-add"
561+
flagHostRemove = "host-rm"
562+
flagHostname = "hostname"
563+
flagEnv = "env"
564+
flagEnvFile = "env-file"
565+
flagEnvRemove = "env-rm"
566+
flagEnvAdd = "env-add"
567+
flagGroup = "group"
568+
flagGroupAdd = "group-add"
569+
flagGroupRemove = "group-rm"
570+
flagLabel = "label"
571+
flagLabelRemove = "label-rm"
572+
flagLabelAdd = "label-add"
573+
flagLimitCPU = "limit-cpu"
574+
flagLimitMemory = "limit-memory"
575+
flagMode = "mode"
576+
flagMount = "mount"
577+
flagMountRemove = "mount-rm"
578+
flagMountAdd = "mount-add"
579+
flagName = "name"
580+
flagNetwork = "network"
581+
flagPublish = "publish"
582+
flagPublishRemove = "publish-rm"
583+
flagPublishAdd = "publish-add"
584+
flagReadOnly = "read-only"
585+
flagReplicas = "replicas"
586+
flagReserveCPU = "reserve-cpu"
587+
flagReserveMemory = "reserve-memory"
588+
flagRestartCondition = "restart-condition"
589+
flagRestartDelay = "restart-delay"
590+
flagRestartMaxAttempts = "restart-max-attempts"
591+
flagRestartWindow = "restart-window"
592+
flagRollbackDelay = "rollback-delay"
593+
flagRollbackFailureAction = "rollback-failure-action"
594+
flagRollbackMaxFailureRatio = "rollback-max-failure-ratio"
595+
flagRollbackMonitor = "rollback-monitor"
596+
flagRollbackParallelism = "rollback-parallelism"
597+
flagStopGracePeriod = "stop-grace-period"
598+
flagStopSignal = "stop-signal"
599+
flagTTY = "tty"
600+
flagUpdateDelay = "update-delay"
601+
flagUpdateFailureAction = "update-failure-action"
602+
flagUpdateMaxFailureRatio = "update-max-failure-ratio"
603+
flagUpdateMonitor = "update-monitor"
604+
flagUpdateParallelism = "update-parallelism"
605+
flagUser = "user"
606+
flagWorkdir = "workdir"
607+
flagRegistryAuth = "with-registry-auth"
608+
flagLogDriver = "log-driver"
609+
flagLogOpt = "log-opt"
610+
flagHealthCmd = "health-cmd"
611+
flagHealthInterval = "health-interval"
612+
flagHealthRetries = "health-retries"
613+
flagHealthTimeout = "health-timeout"
614+
flagNoHealthcheck = "no-healthcheck"
615+
flagSecret = "secret"
616+
flagSecretAdd = "secret-add"
617+
flagSecretRemove = "secret-rm"
596618
)

0 commit comments

Comments
 (0)