Exemple #1
0
func runJoin(dockerCli *client.DockerCli, opts joinOptions) error {
	client := dockerCli.Client()
	ctx := context.Background()

	req := swarm.JoinRequest{
		JoinToken:   opts.token,
		ListenAddr:  opts.listenAddr.String(),
		RemoteAddrs: []string{opts.remote},
	}
	err := client.SwarmJoin(ctx, req)
	if err != nil {
		return err
	}

	info, err := client.Info(ctx)
	if err != nil {
		return err
	}

	_, _, err = client.NodeInspectWithRaw(ctx, info.Swarm.NodeID)
	if err != nil {
		// TODO(aaronl): is there a better way to do this?
		if strings.Contains(err.Error(), "This node is not a swarm manager.") {
			fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a worker.")
		}
	} else {
		fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a manager.")
	}

	return nil
}
Exemple #2
0
func runJoin(dockerCli *client.DockerCli, opts joinOptions) error {
	client := dockerCli.Client()
	ctx := context.Background()

	req := swarm.JoinRequest{
		Manager:     opts.manager,
		Secret:      opts.secret,
		ListenAddr:  opts.listenAddr.String(),
		RemoteAddrs: []string{opts.remote},
		CACertHash:  opts.CACertHash,
	}
	err := client.SwarmJoin(ctx, req)
	if err != nil {
		return err
	}
	if opts.manager {
		fmt.Fprintln(dockerCli.Out(), "This node joined a Swarm as a manager.")
	} else {
		fmt.Fprintln(dockerCli.Out(), "This node joined a Swarm as a worker.")
	}
	return nil
}