MCPcopy Index your code
hub / github.com/docker/cli / runJoinToken

Function runJoinToken

cli/command/swarm/join_token.go:45–99  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, opts joinTokenOptions)

Source from the content-addressed store, hash-verified

43}
44
45func runJoinToken(ctx context.Context, dockerCLI command.Cli, opts joinTokenOptions) error {
46 worker := opts.role == "worker"
47 manager := opts.role == "manager"
48
49 if !worker && !manager {
50 return errors.New("unknown role " + opts.role)
51 }
52
53 apiClient := dockerCLI.Client()
54
55 if opts.rotate {
56 res, err := apiClient.SwarmInspect(ctx, client.SwarmInspectOptions{})
57 if err != nil {
58 return err
59 }
60
61 _, err = apiClient.SwarmUpdate(ctx, client.SwarmUpdateOptions{
62 Version: res.Swarm.Version,
63 Spec: res.Swarm.Spec,
64 RotateWorkerToken: worker,
65 RotateManagerToken: manager,
66 })
67 if err != nil {
68 return err
69 }
70
71 if !opts.quiet {
72 _, _ = fmt.Fprintf(dockerCLI.Out(), "Successfully rotated %s join token.\n\n", opts.role)
73 }
74 }
75
76 // second SwarmInspect in this function,
77 // this is necessary since SwarmUpdate after first changes the join tokens
78 res, err := apiClient.SwarmInspect(ctx, client.SwarmInspectOptions{})
79 if err != nil {
80 return err
81 }
82
83 if opts.quiet && worker {
84 _, _ = fmt.Fprintln(dockerCLI.Out(), res.Swarm.JoinTokens.Worker)
85 return nil
86 }
87
88 if opts.quiet && manager {
89 _, _ = fmt.Fprintln(dockerCLI.Out(), res.Swarm.JoinTokens.Manager)
90 return nil
91 }
92
93 infoResp, err := apiClient.Info(ctx, client.InfoOptions{})
94 if err != nil {
95 return err
96 }
97
98 return printJoinCommand(ctx, dockerCLI, infoResp.Info.Swarm.NodeID, worker, manager)
99}
100
101func printJoinCommand(ctx context.Context, dockerCLI command.Cli, nodeID string, worker bool, manager bool) error {
102 apiClient := dockerCLI.Client()

Callers 1

newJoinTokenCommandFunction · 0.85

Calls 6

printJoinCommandFunction · 0.85
SwarmInspectMethod · 0.80
SwarmUpdateMethod · 0.80
ClientMethod · 0.65
OutMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…