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

Function runJoin

cli/command/swarm/join.go:56–92  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts joinOptions)

Source from the content-addressed store, hash-verified

54}
55
56func runJoin(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts joinOptions) error {
57 apiClient := dockerCLI.Client()
58
59 var availability swarm.NodeAvailability
60 if flags.Changed(flagAvailability) {
61 switch a := swarm.NodeAvailability(strings.ToLower(opts.availability)); a {
62 case swarm.NodeAvailabilityActive, swarm.NodeAvailabilityPause, swarm.NodeAvailabilityDrain:
63 availability = a
64 default:
65 return fmt.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability)
66 }
67 }
68
69 _, err := apiClient.SwarmJoin(ctx, client.SwarmJoinOptions{
70 JoinToken: opts.token,
71 ListenAddr: opts.listenAddr.String(),
72 AdvertiseAddr: opts.advertiseAddr,
73 DataPathAddr: opts.dataPathAddr,
74 RemoteAddrs: []string{opts.remote},
75 Availability: availability,
76 })
77 if err != nil {
78 return err
79 }
80
81 res, err := apiClient.Info(ctx, client.InfoOptions{})
82 if err != nil {
83 return err
84 }
85
86 if res.Info.Swarm.ControlAvailable {
87 _, _ = fmt.Fprintln(dockerCLI.Out(), "This node joined a swarm as a manager.")
88 } else {
89 _, _ = fmt.Fprintln(dockerCLI.Out(), "This node joined a swarm as a worker.")
90 }
91 return nil
92}

Callers 1

newJoinCommandFunction · 0.85

Calls 5

SwarmJoinMethod · 0.80
ClientMethod · 0.65
StringMethod · 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…