diff --git a/cli/manage.go b/cli/manage.go index cb0cec02ab..41b0db85d3 100644 --- a/cli/manage.go +++ b/cli/manage.go @@ -120,9 +120,10 @@ func setupReplication(c *cli.Context, cluster cluster.Cluster, server *api.Serve log.Fatal("Leader election is only supported with consul, etcd and zookeeper discovery.") } client := kvDiscovery.Store() + p := path.Join(kvDiscovery.Prefix(), leaderElectionPath) - candidate := leadership.NewCandidate(client, leaderElectionPath, addr) - follower := leadership.NewFollower(client, leaderElectionPath) + candidate := leadership.NewCandidate(client, p, addr) + follower := leadership.NewFollower(client, p) primary := api.NewPrimary(cluster, tlsConfig, &statusHandler{cluster, candidate, follower}, c.Bool("cors")) replica := api.NewReplica(primary, tlsConfig) diff --git a/discovery/kv/kv.go b/discovery/kv/kv.go index 8a3d2b96f1..44e8d58d16 100644 --- a/discovery/kv/kv.go +++ b/discovery/kv/kv.go @@ -22,6 +22,7 @@ type Discovery struct { store store.Store heartbeat time.Duration ttl time.Duration + prefix string path string } @@ -39,20 +40,19 @@ func Init() { // Initialize is exported func (s *Discovery) Initialize(uris string, heartbeat time.Duration, ttl time.Duration) error { var ( - parts = strings.SplitN(uris, "/", 2) - addrs = strings.Split(parts[0], ",") - prefix = "" - err error + parts = strings.SplitN(uris, "/", 2) + addrs = strings.Split(parts[0], ",") + err error ) // A custom prefix to the path can be optionally used. if len(parts) == 2 { - prefix = parts[1] + s.prefix = parts[1] } s.heartbeat = heartbeat s.ttl = ttl - s.path = path.Join(prefix, discoveryPath) + s.path = path.Join(s.prefix, discoveryPath) // Creates a new store, will ignore options given // if not supported by the chosen store @@ -139,3 +139,8 @@ func (s *Discovery) Register(addr string) error { func (s *Discovery) Store() store.Store { return s.store } + +// Prefix returns the store prefix +func (s *Discovery) Prefix() string { + return s.prefix +}