Browse Source

Merge pull request #24050 from ncoolz/issue-cluster-store-config

Fix check code for --cluster-store and --cluster-advertise in config_…
Vincent Demeester 9 năm trước cách đây
mục cha
commit
2f9d20288c

+ 1 - 1
daemon/config_unix.go

@@ -123,7 +123,7 @@ func (config *Config) GetAllRuntimes() map[string]types.Runtime {
 }
 }
 
 
 func (config *Config) isSwarmCompatible() error {
 func (config *Config) isSwarmCompatible() error {
-	if config.IsValueSet("cluster-store") || config.IsValueSet("cluster-advertise") {
+	if config.ClusterStore != "" || config.ClusterAdvertise != "" {
 		return fmt.Errorf("--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
 		return fmt.Errorf("--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
 	}
 	}
 	if config.LiveRestore {
 	if config.LiveRestore {

+ 24 - 0
integration-cli/docker_cli_swarm_test.go

@@ -4,6 +4,7 @@ package main
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
+	"io/ioutil"
 	"time"
 	"time"
 
 
 	"github.com/docker/docker/pkg/integration/checker"
 	"github.com/docker/docker/pkg/integration/checker"
@@ -134,3 +135,26 @@ func (s *DockerSwarmSuite) TestSwarmInitIPv6(c *check.C) {
 	c.Assert(err, checker.IsNil, check.Commentf("out: %v", out))
 	c.Assert(err, checker.IsNil, check.Commentf("out: %v", out))
 	c.Assert(out, checker.Contains, "Swarm: active")
 	c.Assert(out, checker.Contains, "Swarm: active")
 }
 }
+
+func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *check.C) {
+	// init swarm mode and stop a daemon
+	d := s.AddDaemon(c, true, true)
+	info, err := d.info()
+	c.Assert(err, checker.IsNil)
+	c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
+	c.Assert(d.Stop(), checker.IsNil)
+
+	// start a daemon with --cluster-store and --cluster-advertise
+	err = d.Start("--cluster-store=consul://consuladdr:consulport/some/path", "--cluster-advertise=1.1.1.1:2375")
+	c.Assert(err, checker.NotNil)
+	content, _ := ioutil.ReadFile(d.logFile.Name())
+	c.Assert(string(content), checker.Contains, "--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
+
+	// start a daemon with --live-restore
+	err = d.Start("--live-restore")
+	c.Assert(err, checker.NotNil)
+	content, _ = ioutil.ReadFile(d.logFile.Name())
+	c.Assert(string(content), checker.Contains, "--live-restore daemon configuration is incompatible with swarm mode")
+	// restart for teardown
+	c.Assert(d.Start(), checker.IsNil)
+}