mirror of https://github.com/docker/docs.git
Merge pull request #1048 from aluzzardi/leader-prefix
Leader Election: Use same path prefix as discovery.
This commit is contained in:
commit
1ab4129df6
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue