MCPcopy
hub / github.com/moby/moby / CheckLeader

Method CheckLeader

integration-cli/daemon/daemon_swarm.go:174–193  ·  view source on GitHub ↗

CheckLeader returns whether there is a leader on the swarm or not

(ctx context.Context)

Source from the content-addressed store, hash-verified

172
173// CheckLeader returns whether there is a leader on the swarm or not
174func (d *Daemon) CheckLeader(ctx context.Context) func(t *testing.T) (any, string) {
175 return func(t *testing.T) (any, string) {
176 cli := d.NewClientT(t)
177 defer cli.Close()
178
179 errList := "could not get node list"
180
181 result, err := cli.NodeList(ctx, client.NodeListOptions{})
182 if err != nil {
183 return err, errList
184 }
185
186 for _, node := range result.Items {
187 if node.ManagerStatus != nil && node.ManagerStatus.Leader {
188 return nil, ""
189 }
190 }
191 return errors.New("no leader"), "could not find leader"
192 }
193}
194
195// CmdRetryOutOfSequence tries the specified command against the current daemon
196// up to 10 times, retrying if it encounters an "update out of sequence" error.

Callers 1

Calls 4

NewClientTMethod · 0.95
CloseMethod · 0.65
NodeListMethod · 0.65
NewMethod · 0.65

Tested by 1