mirror of https://github.com/docker/docs.git
Merge pull request #867 from abronan/fix_etcd_sync
Fix etcd SyncCluster and Integration tests
This commit is contained in:
commit
a5b2e57496
|
@ -32,8 +32,8 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "github.com/coreos/go-etcd/etcd",
|
||||
"Comment": "v2.0.0-7-g73a8ef7",
|
||||
"Rev": "73a8ef737e8ea002281a28b4cb92a1de121ad4c6"
|
||||
"Comment": "v2.0.0-11-gcc90c7b",
|
||||
"Rev": "cc90c7b091275e606ad0ca7102a23fb2072f3f5e"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/docker/docker/pkg/ioutils",
|
||||
|
|
|
@ -306,12 +306,16 @@ func (c *Client) GetCluster() []string {
|
|||
}
|
||||
|
||||
// SyncCluster updates the cluster information using the internal machine list.
|
||||
// If no members are found, the intenral machine list is left untouched.
|
||||
func (c *Client) SyncCluster() bool {
|
||||
return c.internalSyncCluster(c.cluster.Machines)
|
||||
}
|
||||
|
||||
// internalSyncCluster syncs cluster information using the given machine list.
|
||||
func (c *Client) internalSyncCluster(machines []string) bool {
|
||||
// comma-separated list of machines in the cluster.
|
||||
members := ""
|
||||
|
||||
for _, machine := range machines {
|
||||
httpPath := c.createHttpPath(machine, path.Join(version, "members"))
|
||||
resp, err := c.httpClient.Get(httpPath)
|
||||
|
@ -333,8 +337,7 @@ func (c *Client) internalSyncCluster(machines []string) bool {
|
|||
// try another machine in the cluster
|
||||
continue
|
||||
}
|
||||
// update Machines List
|
||||
c.cluster.updateFromStr(string(b))
|
||||
members = string(b)
|
||||
} else {
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
@ -354,10 +357,16 @@ func (c *Client) internalSyncCluster(machines []string) bool {
|
|||
urls = append(urls, m.ClientURLs...)
|
||||
}
|
||||
|
||||
// update Machines List
|
||||
c.cluster.updateFromStr(strings.Join(urls, ","))
|
||||
members = strings.Join(urls, ",")
|
||||
}
|
||||
|
||||
// We should never do an empty cluster update.
|
||||
if members == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// update Machines List
|
||||
c.cluster.updateFromStr(members)
|
||||
logger.Debug("sync.machines ", c.cluster.Machines)
|
||||
c.saveConfig()
|
||||
return true
|
||||
|
|
|
@ -28,6 +28,7 @@ var (
|
|||
http.StatusNotFound: true,
|
||||
http.StatusPreconditionFailed: true,
|
||||
http.StatusForbidden: true,
|
||||
http.StatusUnauthorized: true,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -28,6 +28,9 @@ type etcdLock struct {
|
|||
const (
|
||||
defaultLockTTL = 20 * time.Second
|
||||
defaultUpdateTime = 5 * time.Second
|
||||
|
||||
// periodicSync is the time between each call to SyncCluster
|
||||
periodicSync = 10 * time.Minute
|
||||
)
|
||||
|
||||
// InitializeEtcd creates a new Etcd client given
|
||||
|
@ -51,6 +54,12 @@ func InitializeEtcd(addrs []string, options *Config) (Store, error) {
|
|||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
s.client.SyncCluster()
|
||||
time.Sleep(periodicSync)
|
||||
}
|
||||
}()
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
load discovery_helpers
|
||||
|
||||
# Address on which the store will listen (random port between 8000 and 9000).
|
||||
STORE_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 9000 ))
|
||||
# Port and Address on which the store will listen (random port between 8000 and 9000).
|
||||
PORT=$((RANDOM % 1000 + 9000))
|
||||
STORE_HOST=127.0.0.1:$PORT
|
||||
|
||||
# Discovery parameter for Swarm
|
||||
DISCOVERY="etcd://${STORE_HOST}/test"
|
||||
|
@ -12,11 +13,12 @@ DISCOVERY="etcd://${STORE_HOST}/test"
|
|||
CONTAINER_NAME=swarm_etcd
|
||||
|
||||
function start_store() {
|
||||
docker_host run -p $STORE_HOST:4001 \
|
||||
--name=$CONTAINER_NAME -d \
|
||||
docker_host run -d \
|
||||
--net=host \
|
||||
--name=$CONTAINER_NAME \
|
||||
quay.io/coreos/etcd:v2.0.11 \
|
||||
--listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001 \
|
||||
--advertise-client-urls=http://$STORE_HOST
|
||||
--listen-client-urls="http://0.0.0.0:${PORT}" \
|
||||
--advertise-client-urls="http://${STORE_HOST}"
|
||||
}
|
||||
|
||||
function stop_store() {
|
||||
|
|
Loading…
Reference in New Issue