Improve swarm join-token instructions

this change improves the instructions for
swarm join-token and swarm init;

- only print the join-token command for workers
  instead of for both managers and workers, to
  prevent users from copying the wrong command.
  An extra line is added to explain how to obtain
  the manager token.
- print a message that a token was rotated
  sucesfully if '--rotate' is used.
- add some extra white-space before / after
  the join commands, to make copy/pasting
  easier.

this change also does some refactoring of join-token;

- move flagname-constants together with other constants
- use variables for selected role ("worker" / "manager")
  to prevent checking for them multiple times, and to
  keep the "worker" / "manager" sting centralized
- add an extra blank line after "join-token" instructions
  this makes it easier to copy, and cleans up the
  code a tiny bit

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit ebebd41769)
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Sebastiaan van Stijn 2016-07-27 16:14:29 +02:00 committed by Tibor Vass
parent 70f0f7a20e
commit 40baa97ab1
9 changed files with 41 additions and 33 deletions

View file

@ -72,5 +72,10 @@ func runInit(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts initOptions
fmt.Fprintf(dockerCli.Out(), "Swarm initialized: current node (%s) is now a manager.\n\n", nodeID) fmt.Fprintf(dockerCli.Out(), "Swarm initialized: current node (%s) is now a manager.\n\n", nodeID)
return printJoinCommand(ctx, dockerCli, nodeID, true, true) if err := printJoinCommand(ctx, dockerCli, nodeID, true, false); err != nil {
return err
}
fmt.Fprint(dockerCli.Out(), "To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.\n\n")
return nil
} }

View file

@ -12,11 +12,6 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
) )
const (
flagRotate = "rotate"
flagQuiet = "quiet"
)
func newJoinTokenCommand(dockerCli *client.DockerCli) *cobra.Command { func newJoinTokenCommand(dockerCli *client.DockerCli) *cobra.Command {
var rotate, quiet bool var rotate, quiet bool
@ -25,7 +20,10 @@ func newJoinTokenCommand(dockerCli *client.DockerCli) *cobra.Command {
Short: "Manage join tokens", Short: "Manage join tokens",
Args: cli.ExactArgs(1), Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if args[0] != "worker" && args[0] != "manager" { worker := args[0] == "worker"
manager := args[0] == "manager"
if !worker && !manager {
return errors.New("unknown role " + args[0]) return errors.New("unknown role " + args[0])
} }
@ -40,16 +38,16 @@ func newJoinTokenCommand(dockerCli *client.DockerCli) *cobra.Command {
return err return err
} }
if args[0] == "worker" { flags.RotateWorkerToken = worker
flags.RotateWorkerToken = true flags.RotateManagerToken = manager
} else if args[0] == "manager" {
flags.RotateManagerToken = true
}
err = client.SwarmUpdate(ctx, swarm.Version, swarm.Spec, flags) err = client.SwarmUpdate(ctx, swarm.Version, swarm.Spec, flags)
if err != nil { if err != nil {
return err return err
} }
if !quiet {
fmt.Fprintf(dockerCli.Out(), "Succesfully rotated %s join token.\n\n", args[0])
}
} }
swarm, err := client.SwarmInspect(ctx) swarm, err := client.SwarmInspect(ctx)
@ -58,9 +56,9 @@ func newJoinTokenCommand(dockerCli *client.DockerCli) *cobra.Command {
} }
if quiet { if quiet {
if args[0] == "worker" { if worker {
fmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Worker) fmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Worker)
} else if args[0] == "manager" { } else {
fmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Manager) fmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Manager)
} }
} else { } else {
@ -68,7 +66,7 @@ func newJoinTokenCommand(dockerCli *client.DockerCli) *cobra.Command {
if err != nil { if err != nil {
return err return err
} }
return printJoinCommand(ctx, dockerCli, info.Swarm.NodeID, args[0] == "worker", args[0] == "manager") return printJoinCommand(ctx, dockerCli, info.Swarm.NodeID, worker, manager)
} }
return nil return nil
}, },
@ -96,13 +94,10 @@ func printJoinCommand(ctx context.Context, dockerCli *client.DockerCli, nodeID s
if node.ManagerStatus != nil { if node.ManagerStatus != nil {
if worker { if worker {
fmt.Fprintf(dockerCli.Out(), "To add a worker to this swarm, run the following command:\n docker swarm join \\\n --token %s \\\n %s\n", swarm.JoinTokens.Worker, node.ManagerStatus.Addr) fmt.Fprintf(dockerCli.Out(), "To add a worker to this swarm, run the following command:\n\n docker swarm join \\\n --token %s \\\n %s\n\n", swarm.JoinTokens.Worker, node.ManagerStatus.Addr)
} }
if manager { if manager {
if worker { fmt.Fprintf(dockerCli.Out(), "To add a manager to this swarm, run the following command:\n\n docker swarm join \\\n --token %s \\\n %s\n\n", swarm.JoinTokens.Manager, node.ManagerStatus.Addr)
fmt.Fprintln(dockerCli.Out())
}
fmt.Fprintf(dockerCli.Out(), "To add a manager to this swarm, run the following command:\n docker swarm join \\\n --token %s \\\n %s\n", swarm.JoinTokens.Manager, node.ManagerStatus.Addr)
} }
} }

View file

@ -19,6 +19,8 @@ const (
flagDispatcherHeartbeat = "dispatcher-heartbeat" flagDispatcherHeartbeat = "dispatcher-heartbeat"
flagListenAddr = "listen-addr" flagListenAddr = "listen-addr"
flagAdvertiseAddr = "advertise-addr" flagAdvertiseAddr = "advertise-addr"
flagQuiet = "quiet"
flagRotate = "rotate"
flagToken = "token" flagToken = "token"
flagTaskHistoryLimit = "task-history-limit" flagTaskHistoryLimit = "task-history-limit"
flagExternalCA = "external-ca" flagExternalCA = "external-ca"

View file

@ -37,14 +37,12 @@ $ docker swarm init --advertise-addr 192.168.99.121
Swarm initialized: current node (bvz81updecsj6wjz393c09vti) is now a manager. Swarm initialized: current node (bvz81updecsj6wjz393c09vti) is now a manager.
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \ --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \
172.17.0.2:2377 172.17.0.2:2377
To add a manager to this swarm, run the following command: To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
docker swarm join \
--token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 \
172.17.0.2:2377
``` ```
`docker swarm init` generates two random tokens, a worker token and a manager token. When you join `docker swarm init` generates two random tokens, a worker token and a manager token. When you join

View file

@ -36,12 +36,14 @@ the swarm:
```bash ```bash
$ docker swarm join-token worker $ docker swarm join-token worker
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \ --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \
172.17.0.2:2377 172.17.0.2:2377
$ docker swarm join-token manager $ docker swarm join-token manager
To add a manager to this swarm, run the following command: To add a manager to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 \ --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 \
172.17.0.2:2377 172.17.0.2:2377
@ -51,7 +53,10 @@ Use the `--rotate` flag to generate a new join token for the specified role:
```bash ```bash
$ docker swarm join-token --rotate worker $ docker swarm join-token --rotate worker
Succesfully rotated worker join token.
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-b30ljddcqhef9b9v4rs7mel7t \ --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-b30ljddcqhef9b9v4rs7mel7t \
172.17.0.2:2377 172.17.0.2:2377
@ -63,6 +68,7 @@ The `-q` (or `--quiet`) flag only prints the token:
```bash ```bash
$ docker swarm join-token -q worker $ docker swarm join-token -q worker
SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-b30ljddcqhef9b9v4rs7mel7t SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-b30ljddcqhef9b9v4rs7mel7t
``` ```

View file

@ -43,6 +43,7 @@ following command on a manager node:
$ docker swarm join-token worker $ docker swarm join-token worker
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
192.168.99.100:2377 192.168.99.100:2377
@ -90,6 +91,7 @@ following command on a manager node:
$ docker swarm join-token manager $ docker swarm join-token manager
To add a manager to this swarm, run the following command: To add a manager to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-61ztec5kyafptydic6jfc1i33t37flcl4nuipzcusor96k7kby-5vy9t8u35tuqm7vh67lrz9xp6 \ --token SWMTKN-1-61ztec5kyafptydic6jfc1i33t37flcl4nuipzcusor96k7kby-5vy9t8u35tuqm7vh67lrz9xp6 \
192.168.99.100:2377 192.168.99.100:2377

View file

@ -56,21 +56,19 @@ swarm.
external to the swarm. external to the swarm.
The output for `docker swarm init` provides the connection command to use when The output for `docker swarm init` provides the connection command to use when
you join new worker or manager nodes to the swarm: you join new worker nodes to the swarm:
```bash ```bash
$ docker swarm init $ docker swarm init
Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager. Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
192.168.99.100:2377 192.168.99.100:2377
To add a manager to this swarm, run the following command: To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
docker swarm join \
--token SWMTKN-1-61ztec5kyafptydic6jfc1i33t37flcl4nuipzcusor96k7kby-5vy9t8u35tuqm7vh67lrz9xp6 \
192.168.99.100:2377
``` ```
### Configure the advertise address ### Configure the advertise address
@ -115,6 +113,7 @@ To retrieve the join command including the join token for worker nodes, run:
$ docker swarm join-token worker $ docker swarm join-token worker
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
192.168.99.100:2377 192.168.99.100:2377
@ -128,6 +127,7 @@ To view the join command and token for manager nodes, run:
$ docker swarm join-token manager $ docker swarm join-token manager
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
192.168.99.100:2377 192.168.99.100:2377
@ -167,6 +167,7 @@ nodes:
$docker swarm join-token --rotate worker $docker swarm join-token --rotate worker
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-2kscvs0zuymrsc9t0ocyy1rdns9dhaodvpl639j2bqx55uptag-ebmn5u927reawo27s3azntd44 \ --token SWMTKN-1-2kscvs0zuymrsc9t0ocyy1rdns9dhaodvpl639j2bqx55uptag-ebmn5u927reawo27s3azntd44 \
172.17.0.2:2377 172.17.0.2:2377

View file

@ -36,6 +36,7 @@ This tutorial uses the name `worker1`.
$ docker swarm join-token worker $ docker swarm join-token worker
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
192.168.99.100:2377 192.168.99.100:2377

View file

@ -33,14 +33,12 @@ node. For example, the tutorial uses a machine named `manager1`.
Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager. Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.
To add a worker to this swarm, run the following command: To add a worker to this swarm, run the following command:
docker swarm join \ docker swarm join \
--token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
192.168.99.100:2377 192.168.99.100:2377
To add a manager to this swarm, run the following command: To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
docker swarm join \
--token SWMTKN-1-61ztec5kyafptydic6jfc1i33t37flcl4nuipzcusor96k7kby-5vy9t8u35tuqm7vh67lrz9xp6 \
192.168.99.100:2377
``` ```
The `--advertise-addr` flag configures the manager node to publish its The `--advertise-addr` flag configures the manager node to publish its