@@ -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+
168178type 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
522539const (
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