From e0f229d2caa4a46f06a327deffcfea80fceff915 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Thu, 25 Aug 2016 21:08:53 -0700 Subject: [PATCH] Let swarmkit handle cluster defaults in `swarm init` if not specified This fix tries to address the issue raised in 24958 where previously `docker swarm init` will automatically fill in all the default value (instead of letting swarmkit to handle the default). This fix update the `swarm init` so that initial value are passed only when a flag change has been detected. This fix fixes 24958. Signed-off-by: Yong Tang --- command/swarm/init.go | 2 +- command/swarm/opts.go | 19 ++++++++++++++----- command/swarm/update.go | 3 ++- command/system/info.go | 6 +++++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/command/swarm/init.go b/command/swarm/init.go index 9a17224bde..60fb8e8fe3 100644 --- a/command/swarm/init.go +++ b/command/swarm/init.go @@ -59,7 +59,7 @@ func runInit(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts initOption ListenAddr: opts.listenAddr.String(), AdvertiseAddr: opts.advertiseAddr, ForceNewCluster: opts.forceNewCluster, - Spec: opts.swarmOptions.ToSpec(), + Spec: opts.swarmOptions.ToSpec(flags), } nodeID, err := client.SwarmInit(ctx, req) diff --git a/command/swarm/opts.go b/command/swarm/opts.go index 7fcf25d136..58330b7f8a 100644 --- a/command/swarm/opts.go +++ b/command/swarm/opts.go @@ -169,11 +169,20 @@ func addSwarmFlags(flags *pflag.FlagSet, opts *swarmOptions) { flags.Var(&opts.externalCA, flagExternalCA, "Specifications of one or more certificate signing endpoints") } -func (opts *swarmOptions) ToSpec() swarm.Spec { +func (opts *swarmOptions) ToSpec(flags *pflag.FlagSet) swarm.Spec { spec := swarm.Spec{} - spec.Orchestration.TaskHistoryRetentionLimit = opts.taskHistoryLimit - spec.Dispatcher.HeartbeatPeriod = opts.dispatcherHeartbeat - spec.CAConfig.NodeCertExpiry = opts.nodeCertExpiry - spec.CAConfig.ExternalCAs = opts.externalCA.Value() + + if flags.Changed(flagTaskHistoryLimit) { + spec.Orchestration.TaskHistoryRetentionLimit = &opts.taskHistoryLimit + } + if flags.Changed(flagDispatcherHeartbeat) { + spec.Dispatcher.HeartbeatPeriod = opts.dispatcherHeartbeat + } + if flags.Changed(flagCertExpiry) { + spec.CAConfig.NodeCertExpiry = opts.nodeCertExpiry + } + if flags.Changed(flagExternalCA) { + spec.CAConfig.ExternalCAs = opts.externalCA.Value() + } return spec } diff --git a/command/swarm/update.go b/command/swarm/update.go index 9884b79169..71451e450c 100644 --- a/command/swarm/update.go +++ b/command/swarm/update.go @@ -58,7 +58,8 @@ func mergeSwarm(swarm *swarm.Swarm, flags *pflag.FlagSet) error { spec := &swarm.Spec if flags.Changed(flagTaskHistoryLimit) { - spec.Orchestration.TaskHistoryRetentionLimit, _ = flags.GetInt64(flagTaskHistoryLimit) + taskHistoryRetentionLimit, _ := flags.GetInt64(flagTaskHistoryLimit) + spec.Orchestration.TaskHistoryRetentionLimit = &taskHistoryRetentionLimit } if flags.Changed(flagDispatcherHeartbeat) { diff --git a/command/system/info.go b/command/system/info.go index a2d0abad23..1debf755f1 100644 --- a/command/system/info.go +++ b/command/system/info.go @@ -107,7 +107,11 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error { fmt.Fprintf(dockerCli.Out(), " Managers: %d\n", info.Swarm.Managers) fmt.Fprintf(dockerCli.Out(), " Nodes: %d\n", info.Swarm.Nodes) fmt.Fprintf(dockerCli.Out(), " Orchestration:\n") - fmt.Fprintf(dockerCli.Out(), " Task History Retention Limit: %d\n", info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit) + taskHistoryRetentionLimit := int64(0) + if info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit != nil { + taskHistoryRetentionLimit = *info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit + } + fmt.Fprintf(dockerCli.Out(), " Task History Retention Limit: %d\n", taskHistoryRetentionLimit) fmt.Fprintf(dockerCli.Out(), " Raft:\n") fmt.Fprintf(dockerCli.Out(), " Snapshot Interval: %d\n", info.Swarm.Cluster.Spec.Raft.SnapshotInterval) fmt.Fprintf(dockerCli.Out(), " Heartbeat Tick: %d\n", info.Swarm.Cluster.Spec.Raft.HeartbeatTick)