mirror of https://github.com/docker/cli.git
Add support for rollback flags
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
5232868f46
commit
8de01fb7a8
|
@ -57,6 +57,18 @@ UpdateConfig:
|
|||
{{- end }}
|
||||
Max failure ratio: {{ .UpdateMaxFailureRatio }}
|
||||
{{- end }}
|
||||
{{- if .HasRollbackConfig }}
|
||||
RollbackConfig:
|
||||
Parallelism: {{ .RollbackParallelism }}
|
||||
{{- if .HasRollbackDelay}}
|
||||
Delay: {{ .RollbackDelay }}
|
||||
{{- end }}
|
||||
On failure: {{ .RollbackOnFailure }}
|
||||
{{- if .HasRollbackMonitor}}
|
||||
Monitoring Period: {{ .RollbackMonitor }}
|
||||
{{- end }}
|
||||
Max failure ratio: {{ .RollbackMaxFailureRatio }}
|
||||
{{- end }}
|
||||
ContainerSpec:
|
||||
Image: {{ .ContainerImage }}
|
||||
{{- if .ContainerArgs }}
|
||||
|
@ -259,6 +271,38 @@ func (ctx *serviceInspectContext) UpdateMaxFailureRatio() float32 {
|
|||
return ctx.Service.Spec.UpdateConfig.MaxFailureRatio
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) HasRollbackConfig() bool {
|
||||
return ctx.Service.Spec.RollbackConfig != nil
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) RollbackParallelism() uint64 {
|
||||
return ctx.Service.Spec.RollbackConfig.Parallelism
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) HasRollbackDelay() bool {
|
||||
return ctx.Service.Spec.RollbackConfig.Delay.Nanoseconds() > 0
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) RollbackDelay() time.Duration {
|
||||
return ctx.Service.Spec.RollbackConfig.Delay
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) RollbackOnFailure() string {
|
||||
return ctx.Service.Spec.RollbackConfig.FailureAction
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) HasRollbackMonitor() bool {
|
||||
return ctx.Service.Spec.RollbackConfig.Monitor.Nanoseconds() > 0
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) RollbackMonitor() time.Duration {
|
||||
return ctx.Service.Spec.RollbackConfig.Monitor
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) RollbackMaxFailureRatio() float32 {
|
||||
return ctx.Service.Spec.RollbackConfig.MaxFailureRatio
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) ContainerImage() string {
|
||||
return ctx.Service.Spec.TaskTemplate.ContainerSpec.Image
|
||||
}
|
||||
|
|
|
@ -49,7 +49,6 @@ func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time)
|
|||
Replicas: &two,
|
||||
},
|
||||
},
|
||||
UpdateConfig: nil,
|
||||
Networks: []swarm.NetworkAttachmentConfig{
|
||||
{
|
||||
Target: "5vpyomhb6ievnk0i0o60gcnei",
|
||||
|
|
|
@ -165,6 +165,16 @@ type updateOptions struct {
|
|||
maxFailureRatio floatValue
|
||||
}
|
||||
|
||||
func (opts updateOptions) config() *swarm.UpdateConfig {
|
||||
return &swarm.UpdateConfig{
|
||||
Parallelism: opts.parallelism,
|
||||
Delay: opts.delay,
|
||||
Monitor: opts.monitor,
|
||||
FailureAction: opts.onFailure,
|
||||
MaxFailureRatio: opts.maxFailureRatio.Value(),
|
||||
}
|
||||
}
|
||||
|
||||
type resourceOptions struct {
|
||||
limitCPU opts.NanoCPUs
|
||||
limitMemBytes opts.MemBytes
|
||||
|
@ -328,6 +338,7 @@ type serviceOptions struct {
|
|||
constraints opts.ListOpts
|
||||
placementPrefs placementPrefOpts
|
||||
update updateOptions
|
||||
rollback updateOptions
|
||||
networks opts.ListOpts
|
||||
endpoint endpointOptions
|
||||
|
||||
|
@ -447,13 +458,8 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
|||
},
|
||||
Networks: convertNetworks(opts.networks.GetAll()),
|
||||
Mode: serviceMode,
|
||||
UpdateConfig: &swarm.UpdateConfig{
|
||||
Parallelism: opts.update.parallelism,
|
||||
Delay: opts.update.delay,
|
||||
Monitor: opts.update.monitor,
|
||||
FailureAction: opts.update.onFailure,
|
||||
MaxFailureRatio: opts.update.maxFailureRatio.Value(),
|
||||
},
|
||||
UpdateConfig: opts.update.config(),
|
||||
RollbackConfig: opts.rollback.config(),
|
||||
EndpointSpec: opts.endpoint.ToEndpointSpec(),
|
||||
}
|
||||
|
||||
|
@ -491,6 +497,17 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
|
|||
flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update")
|
||||
flags.SetAnnotation(flagUpdateMaxFailureRatio, "version", []string{"1.25"})
|
||||
|
||||
flags.Uint64Var(&opts.rollback.parallelism, flagRollbackParallelism, 1, "Maximum number of tasks rolled back simultaneously (0 to roll back all at once)")
|
||||
flags.SetAnnotation(flagRollbackParallelism, "version", []string{"1.27"})
|
||||
flags.DurationVar(&opts.rollback.delay, flagRollbackDelay, time.Duration(0), "Delay between task rollbacks (ns|us|ms|s|m|h) (default 0s)")
|
||||
flags.SetAnnotation(flagRollbackDelay, "version", []string{"1.27"})
|
||||
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)")
|
||||
flags.SetAnnotation(flagRollbackMonitor, "version", []string{"1.27"})
|
||||
flags.StringVar(&opts.rollback.onFailure, flagRollbackFailureAction, "pause", `Action on rollback failure ("pause"|"continue")`)
|
||||
flags.SetAnnotation(flagRollbackFailureAction, "version", []string{"1.27"})
|
||||
flags.Var(&opts.rollback.maxFailureRatio, flagRollbackMaxFailureRatio, "Failure rate to tolerate during a rollback")
|
||||
flags.SetAnnotation(flagRollbackMaxFailureRatio, "version", []string{"1.27"})
|
||||
|
||||
flags.StringVar(&opts.endpoint.mode, flagEndpointMode, "vip", "Endpoint mode (vip or dnsrr)")
|
||||
|
||||
flags.BoolVar(&opts.registryAuth, flagRegistryAuth, false, "Send registry authentication details to swarm agents")
|
||||
|
@ -572,6 +589,11 @@ const (
|
|||
flagRestartDelay = "restart-delay"
|
||||
flagRestartMaxAttempts = "restart-max-attempts"
|
||||
flagRestartWindow = "restart-window"
|
||||
flagRollbackDelay = "rollback-delay"
|
||||
flagRollbackFailureAction = "rollback-failure-action"
|
||||
flagRollbackMaxFailureRatio = "rollback-max-failure-ratio"
|
||||
flagRollbackMonitor = "rollback-monitor"
|
||||
flagRollbackParallelism = "rollback-parallelism"
|
||||
flagStopGracePeriod = "stop-grace-period"
|
||||
flagStopSignal = "stop-signal"
|
||||
flagTTY = "tty"
|
||||
|
|
|
@ -289,6 +289,17 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|||
updateFloatValue(flagUpdateMaxFailureRatio, &spec.UpdateConfig.MaxFailureRatio)
|
||||
}
|
||||
|
||||
if anyChanged(flags, flagRollbackParallelism, flagRollbackDelay, flagRollbackMonitor, flagRollbackFailureAction, flagRollbackMaxFailureRatio) {
|
||||
if spec.RollbackConfig == nil {
|
||||
spec.RollbackConfig = &swarm.UpdateConfig{}
|
||||
}
|
||||
updateUint64(flagRollbackParallelism, &spec.RollbackConfig.Parallelism)
|
||||
updateDuration(flagRollbackDelay, &spec.RollbackConfig.Delay)
|
||||
updateDuration(flagRollbackMonitor, &spec.RollbackConfig.Monitor)
|
||||
updateString(flagRollbackFailureAction, &spec.RollbackConfig.FailureAction)
|
||||
updateFloatValue(flagRollbackMaxFailureRatio, &spec.RollbackConfig.MaxFailureRatio)
|
||||
}
|
||||
|
||||
if flags.Changed(flagEndpointMode) {
|
||||
value, _ := flags.GetString(flagEndpointMode)
|
||||
if spec.EndpointSpec == nil {
|
||||
|
|
Loading…
Reference in New Issue