CheckLeader returns whether there is a leader on the swarm or not
(ctx context.Context)
| 172 | |
| 173 | // CheckLeader returns whether there is a leader on the swarm or not |
| 174 | func (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. |