From e6e1fd5d0657c3ab5b15c2984403e4a4e62ca2bb Mon Sep 17 00:00:00 2001 From: "Arnaud Porterie (icecrime)" Date: Tue, 14 Jun 2016 17:36:37 -0700 Subject: [PATCH] Make `--dispatcher-heartbeat-period` a duration Make `--dispatcher-heartbeat-period` a duration in `docker swarm update`, allowing to express the value as "5s", "1h", etc. Signed-off-by: Arnaud Porterie (icecrime) --- api/client/swarm/update.go | 17 ++++++++++------- contrib/completion/bash/docker | 2 +- docs/reference/commandline/swarm_update.md | 19 ++++++++++--------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/api/client/swarm/update.go b/api/client/swarm/update.go index 59aef4c8af..0a851a632a 100644 --- a/api/client/swarm/update.go +++ b/api/client/swarm/update.go @@ -2,6 +2,7 @@ package swarm import ( "fmt" + "time" "golang.org/x/net/context" @@ -13,10 +14,10 @@ import ( ) type updateOptions struct { - autoAccept AutoAcceptOption - secret string - taskHistoryLimit int64 - heartbeatPeriod uint64 + autoAccept AutoAcceptOption + secret string + taskHistoryLimit int64 + dispatcherHeartbeat time.Duration } func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command { @@ -36,7 +37,7 @@ func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command { flags.Var(&opts.autoAccept, "auto-accept", "Auto acceptance policy (worker, manager or none)") flags.StringVar(&opts.secret, "secret", "", "Set secret value needed to accept nodes into cluster") flags.Int64Var(&opts.taskHistoryLimit, "task-history-limit", 10, "Task history retention limit") - flags.Uint64Var(&opts.heartbeatPeriod, "dispatcher-heartbeat-period", 5000000000, "Dispatcher heartbeat period") + flags.DurationVar(&opts.dispatcherHeartbeat, "dispatcher-heartbeat", time.Duration(5*time.Second), "Dispatcher heartbeat period") return cmd } @@ -85,8 +86,10 @@ func mergeSwarm(swarm *swarm.Swarm, flags *pflag.FlagSet) error { spec.Orchestration.TaskHistoryRetentionLimit, _ = flags.GetInt64("task-history-limit") } - if flags.Changed("dispatcher-heartbeat-period") { - spec.Dispatcher.HeartbeatPeriod, _ = flags.GetUint64("dispatcher-heartbeat-period") + if flags.Changed("dispatcher-heartbeat") { + if v, err := flags.GetDuration("dispatcher-heartbeat"); err == nil { + spec.Dispatcher.HeartbeatPeriod = uint64(v.Nanoseconds()) + } } return nil diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 180e95ab7b..abde5ce14c 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -1641,7 +1641,7 @@ _docker_swarm_join() { _docker_swarm_update() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--auto-accept --dispatcher-heartbeat-period --help --secret --task-history-limit" -- "$cur" ) ) + COMPREPLY=( $( compgen -W "--auto-accept --dispatcher-heartbeat --help --secret --task-history-limit" -- "$cur" ) ) ;; esac } diff --git a/docs/reference/commandline/swarm_update.md b/docs/reference/commandline/swarm_update.md index 26a06a734c..942a330ea1 100644 --- a/docs/reference/commandline/swarm_update.md +++ b/docs/reference/commandline/swarm_update.md @@ -12,15 +12,16 @@ parent = "smn_cli" # swarm update - Usage: docker swarm update [OPTIONS] - - update the Swarm. - - Options: - --auto-accept value Acceptance policy (default [worker,manager]) - --help Print usage - --secret string Set secret value needed to accept nodes into cluster - + Usage: docker swarm update [OPTIONS] + + update the Swarm. + + Options: + --auto-accept value Auto acceptance policy (worker, manager or none) + --dispatcher-heartbeat duration Dispatcher heartbeat period (default 5s) + --help Print usage + --secret string Set secret value needed to accept nodes into cluster + --task-history-limit int Task history retention limit (default 10) Updates a Swarm cluster with new parameter values. This command must target a manager node.