Boot bootstrap a builder
(ctx context.Context)
| 160 | |
| 161 | // Boot bootstrap a builder |
| 162 | func (b *Builder) Boot(ctx context.Context) (bool, error) { |
| 163 | toBoot := make([]int, 0, len(b.nodes)) |
| 164 | for idx, d := range b.nodes { |
| 165 | if d.Err != nil || d.Driver == nil || d.DriverInfo == nil { |
| 166 | continue |
| 167 | } |
| 168 | if d.DriverInfo.Status != driver.Running { |
| 169 | toBoot = append(toBoot, idx) |
| 170 | } |
| 171 | } |
| 172 | if len(toBoot) == 0 { |
| 173 | return false, nil |
| 174 | } |
| 175 | |
| 176 | printer, err := progress.NewPrinter(context.TODO(), os.Stderr, progressui.AutoMode) |
| 177 | if err != nil { |
| 178 | return false, err |
| 179 | } |
| 180 | |
| 181 | baseCtx := ctx |
| 182 | eg, _ := errgroup.WithContext(ctx) |
| 183 | errCh := make(chan error, len(toBoot)) |
| 184 | for _, idx := range toBoot { |
| 185 | func(idx int) { |
| 186 | eg.Go(func() error { |
| 187 | pw := progress.WithPrefix(printer, b.NodeGroup.Nodes[idx].Name, len(toBoot) > 1) |
| 188 | _, err := driver.Boot(ctx, baseCtx, b.nodes[idx].Driver, pw) |
| 189 | if err != nil { |
| 190 | b.nodes[idx].Err = err |
| 191 | errCh <- err |
| 192 | } |
| 193 | return nil |
| 194 | }) |
| 195 | }(idx) |
| 196 | } |
| 197 | |
| 198 | err = eg.Wait() |
| 199 | close(errCh) |
| 200 | err1 := printer.Wait() |
| 201 | if err == nil { |
| 202 | err = err1 |
| 203 | } |
| 204 | |
| 205 | if err == nil && len(errCh) > 0 { |
| 206 | return false, <-errCh |
| 207 | } |
| 208 | return true, err |
| 209 | } |
| 210 | |
| 211 | // Inactive checks if all nodes are inactive for this builder. |
| 212 | func (b *Builder) Inactive() bool { |
no test coverage detected