Merge pull request #858 from aluzzardi/addr-flag

Replace --addr with --advertise
This commit is contained in:
Alexandre Beslic 2015-05-27 11:44:41 -07:00
commit 23f66f8cc6
9 changed files with 41 additions and 28 deletions

View File

@ -114,7 +114,7 @@ func Run() {
flStore,
flStrategy, flFilter,
flHosts,
flLeaderElection, flAddr,
flLeaderElection, flManageAdvertise,
flTLS, flTLSCaCert, flTLSCert, flTLSKey, flTLSVerify,
flHeartBeat,
flEnableCors,
@ -125,7 +125,7 @@ func Run() {
Name: "join",
ShortName: "j",
Usage: "join a docker cluster",
Flags: []cli.Flag{flAddr, flHeartBeat, flTTL},
Flags: []cli.Flag{flJoinAdvertise, flHeartBeat, flTTL},
Action: join,
},
}

View File

@ -32,13 +32,16 @@ var (
Value: homepath(".swarm"),
Usage: "",
}
flAddr = cli.StringFlag{
Name: "addr",
Value: "127.0.0.1:2375",
Usage: "ip to advertise",
EnvVar: "SWARM_ADDR",
flJoinAdvertise = cli.StringFlag{
Name: "advertise, addr",
Usage: "Address of the Docker Engine joining the cluster. Swarm managers MUST be able to reach Docker at this address.",
EnvVar: "SWARM_ADVERTISE",
}
flManageAdvertise = cli.StringFlag{
Name: "advertise, addr",
Usage: "Address of the Swarm manager joining the cluster. Other swarm managers MUST be able to reach Swarm at this address.",
EnvVar: "SWARM_ADVERTISE",
}
// hack for go vet
flHostsValue = cli.StringSlice([]string{"tcp://127.0.0.1:2375"})

View File

@ -20,6 +20,14 @@ func join(c *cli.Context) {
log.Fatalf("discovery required to join a cluster. See '%s join --help'.", c.App.Name)
}
addr := c.String("advertise")
if addr == "" {
log.Fatal("missing mandatory --advertise flag")
}
if !checkAddrFormat(addr) {
log.Fatal("--advertise should be of the form ip:port or hostname:port")
}
hb, err := time.ParseDuration(c.String("heartbeat"))
if err != nil {
log.Fatalf("invalid --heartbeat: %v", err)
@ -39,12 +47,6 @@ func join(c *cli.Context) {
log.Fatal(err)
}
addr := c.String("addr")
if !checkAddrFormat(addr) {
log.Fatal("--addr should be of the form ip:port or hostname:port")
}
for {
log.WithFields(log.Fields{"addr": addr, "discovery": dflag}).Infof("Registering on the discovery service every %s...", hb)
if err := d.Register(addr); err != nil {

View File

@ -211,7 +211,15 @@ func manage(c *cli.Context) {
router := api.NewRouter(cl, tlsConfig, c.Bool("cors"))
if c.Bool("leader-election") {
setupLeaderElection(server, router, discovery, c.String("addr"), tlsConfig)
addr := c.String("advertise")
if addr == "" {
log.Fatal("--advertise address must be provided when using --leader-election")
}
if !checkAddrFormat(addr) {
log.Fatal("--advertise should be of the form ip:port or hostname:port")
}
setupLeaderElection(server, router, discovery, addr, tlsConfig)
} else {
server.SetHandler(router)
}

View File

@ -26,7 +26,7 @@ Then we create each node and join them to the cluster.
# on each of your nodes, start the swarm agent
# <node_ip> doesn't have to be public (eg. 192.168.0.X),
# as long as the swarm manager can access it.
$ swarm join --addr=<node_ip:2375> token://<cluster_id>
$ swarm join --advertise=<node_ip:2375> token://<cluster_id>
```
Finally, we start the Swarm manager. This can be on any machine or even
@ -95,7 +95,7 @@ On each of your nodes, start the Swarm agent. The node IP address
doesn't have to be public as long as the swarm manager can access it.
```bash
swarm join --addr=<node_ip:2375> etcd://<etcd_ip>/<path>
swarm join --advertise=<node_ip:2375> etcd://<etcd_ip>/<path>
```
Start the manager on any machine or your laptop.
@ -127,7 +127,7 @@ On each of your nodes, start the Swarm agent. The node IP address
doesn't need to be public as long as the Swarm manager can access it.
```bash
swarm join --addr=<node_ip:2375> consul://<consul_addr>/<path>
swarm join --advertise=<node_ip:2375> consul://<consul_addr>/<path>
```
Start the manager on any machine or your laptop.
@ -159,7 +159,7 @@ On each of your nodes, start the Swarm agent. The node IP doesn't have
to be public as long as the swarm manager can access it.
```bash
swarm join --addr=<node_ip:2375> zk://<zookeeper_addr1>,<zookeeper_addr2>/<path>
swarm join --advertise=<node_ip:2375> zk://<zookeeper_addr1>,<zookeeper_addr2>/<path>
```
Start the manager on any machine or your laptop.

View File

@ -26,7 +26,7 @@ Then we create each node and join them to the cluster.
# on each of your nodes, start the swarm agent
# <node_ip> doesn't have to be public (eg. 192.168.0.X),
# as long as the swarm manager can access it.
$ swarm join --addr=<node_ip:2375> token://<cluster_id>
$ swarm join --advertise=<node_ip:2375> token://<cluster_id>
```
Finally, we start the Swarm manager. This can be on any machine or even
@ -95,7 +95,7 @@ On each of your nodes, start the Swarm agent. The node IP address
doesn't have to be public as long as the swarm manager can access it.
```bash
swarm join --addr=<node_ip:2375> etcd://<etcd_addr1>,<etcd_addr2>/<optional path prefix>
swarm join --advertise=<node_ip:2375> etcd://<etcd_addr1>,<etcd_addr2>/<optional path prefix>
```
Start the manager on any machine or your laptop.
@ -127,7 +127,7 @@ On each of your nodes, start the Swarm agent. The node IP address
doesn't need to be public as long as the Swarm manager can access it.
```bash
swarm join --addr=<node_ip:2375> consul://<consul_addr>/<optional path prefix>
swarm join --advertise=<node_ip:2375> consul://<consul_addr>/<optional path prefix>
```
Start the manager on any machine or your laptop.
@ -159,7 +159,7 @@ On each of your nodes, start the Swarm agent. The node IP doesn't have
to be public as long as the swarm manager can access it.
```bash
swarm join --addr=<node_ip:2375> zk://<zookeeper_addr1>,<zookeeper_addr2>/<optional path prefix>
swarm join --advertise=<node_ip:2375> zk://<zookeeper_addr1>,<zookeeper_addr2>/<optional path prefix>
```
Start the manager on any machine or your laptop.

View File

@ -41,14 +41,14 @@ For instance, let's start `node-1` with the `storage=ssd` label:
```bash
$ docker -d --label storage=ssd
$ swarm join --addr=192.168.0.42:2375 token://XXXXXXXXXXXXXXXXXX
$ swarm join --advertise=192.168.0.42:2375 token://XXXXXXXXXXXXXXXXXX
```
Again, but this time `node-2` with `storage=disk`:
```bash
$ docker -d --label storage=disk
$ swarm join --addr=192.168.0.43:2375 token://XXXXXXXXXXXXXXXXXX
$ swarm join --advertise=192.168.0.43:2375 token://XXXXXXXXXXXXXXXXXX
```
Once the nodes are registered with the cluster, the master pulls their respective

View File

@ -41,14 +41,14 @@ For instance, let's start `node-1` with the `storage=ssd` label:
```bash
$ docker -d --label storage=ssd
$ swarm join --addr=192.168.0.42:2375 token://XXXXXXXXXXXXXXXXXX
$ swarm join --advertise=192.168.0.42:2375 token://XXXXXXXXXXXXXXXXXX
```
Again, but this time `node-2` with `storage=disk`:
```bash
$ docker -d --label storage=disk
$ swarm join --addr=192.168.0.43:2375 token://XXXXXXXXXXXXXXXXXX
$ swarm join --advertise=192.168.0.43:2375 token://XXXXXXXXXXXXXXXXXX
```
Once the nodes are registered with the cluster, the master pulls their respective

View File

@ -117,7 +117,7 @@ function swarm_join() {
for ((i=current; i < nodes; i++)); do
local h="${HOSTS[$i]}"
echo "Swarm join #${i}: $h $addr"
"$SWARM_BINARY" -l debug join --heartbeat=1s --ttl=10s --addr="$h" "$addr" &
"$SWARM_BINARY" -l debug join --heartbeat=1s --ttl=10s --advertise="$h" "$addr" &
SWARM_JOIN_PID[$i]=$!
done
}