|
@@ -23,23 +23,22 @@ type updateOptions struct {
|
|
|
|
|
|
func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
|
opts := updateOptions{autoAccept: NewAutoAcceptOption()}
|
|
|
- var flags *pflag.FlagSet
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
Use: "update",
|
|
|
Short: "Update the Swarm",
|
|
|
Args: cli.NoArgs,
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
- return runUpdate(dockerCli, flags, opts)
|
|
|
+ return runUpdate(dockerCli, cmd.Flags(), opts)
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- flags = cmd.Flags()
|
|
|
- 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.DurationVar(&opts.dispatcherHeartbeat, "dispatcher-heartbeat", time.Duration(5*time.Second), "Dispatcher heartbeat period")
|
|
|
- flags.DurationVar(&opts.nodeCertExpiry, "cert-expiry", time.Duration(90*24*time.Hour), "Validity period for node certificates")
|
|
|
+ flags := cmd.Flags()
|
|
|
+ flags.Var(&opts.autoAccept, flagAutoAccept, "Auto acceptance policy (worker, manager or none)")
|
|
|
+ flags.StringVar(&opts.secret, flagSecret, "", "Set secret value needed to accept nodes into cluster")
|
|
|
+ flags.Int64Var(&opts.taskHistoryLimit, flagTaskHistoryLimit, 10, "Task history retention limit")
|
|
|
+ flags.DurationVar(&opts.dispatcherHeartbeat, flagDispatcherHeartbeat, time.Duration(5*time.Second), "Dispatcher heartbeat period")
|
|
|
+ flags.DurationVar(&opts.nodeCertExpiry, flagCertExpiry, time.Duration(90*24*time.Hour), "Validity period for node certificates")
|
|
|
return cmd
|
|
|
}
|
|
|
|
|
@@ -69,14 +68,14 @@ func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts updateOpt
|
|
|
func mergeSwarm(swarm *swarm.Swarm, flags *pflag.FlagSet) error {
|
|
|
spec := &swarm.Spec
|
|
|
|
|
|
- if flags.Changed("auto-accept") {
|
|
|
- value := flags.Lookup("auto-accept").Value.(*AutoAcceptOption)
|
|
|
+ if flags.Changed(flagAutoAccept) {
|
|
|
+ value := flags.Lookup(flagAutoAccept).Value.(*AutoAcceptOption)
|
|
|
spec.AcceptancePolicy.Policies = value.Policies(nil)
|
|
|
}
|
|
|
|
|
|
var psecret *string
|
|
|
- if flags.Changed("secret") {
|
|
|
- secret, _ := flags.GetString("secret")
|
|
|
+ if flags.Changed(flagSecret) {
|
|
|
+ secret, _ := flags.GetString(flagSecret)
|
|
|
psecret = &secret
|
|
|
}
|
|
|
|
|
@@ -84,18 +83,18 @@ func mergeSwarm(swarm *swarm.Swarm, flags *pflag.FlagSet) error {
|
|
|
spec.AcceptancePolicy.Policies[i].Secret = psecret
|
|
|
}
|
|
|
|
|
|
- if flags.Changed("task-history-limit") {
|
|
|
- spec.Orchestration.TaskHistoryRetentionLimit, _ = flags.GetInt64("task-history-limit")
|
|
|
+ if flags.Changed(flagTaskHistoryLimit) {
|
|
|
+ spec.Orchestration.TaskHistoryRetentionLimit, _ = flags.GetInt64(flagTaskHistoryLimit)
|
|
|
}
|
|
|
|
|
|
- if flags.Changed("dispatcher-heartbeat") {
|
|
|
- if v, err := flags.GetDuration("dispatcher-heartbeat"); err == nil {
|
|
|
+ if flags.Changed(flagDispatcherHeartbeat) {
|
|
|
+ if v, err := flags.GetDuration(flagDispatcherHeartbeat); err == nil {
|
|
|
spec.Dispatcher.HeartbeatPeriod = uint64(v.Nanoseconds())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if flags.Changed("cert-expiry") {
|
|
|
- if v, err := flags.GetDuration("cert-expiry"); err == nil {
|
|
|
+ if flags.Changed(flagCertExpiry) {
|
|
|
+ if v, err := flags.GetDuration(flagCertExpiry); err == nil {
|
|
|
spec.CAConfig.NodeCertExpiry = v
|
|
|
}
|
|
|
}
|