diff --git a/builder/node.go b/builder/node.go index 729be8c3754..e4e22a91df0 100644 --- a/builder/node.go +++ b/builder/node.go @@ -42,9 +42,28 @@ func (b *Builder) Nodes() []Node { return b.nodes } +type LoadNodesOption func(*loadNodesOptions) + +type loadNodesOptions struct { + data bool +} + +func WithData() LoadNodesOption { + return func(o *loadNodesOptions) { + o.data = true + } +} + // LoadNodes loads and returns nodes for this builder. // TODO: this should be a method on a Node object and lazy load data for each driver. -func (b *Builder) LoadNodes(ctx context.Context, withData bool) (_ []Node, err error) { +func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []Node, err error) { + lno := loadNodesOptions{ + data: false, + } + for _, opt := range opts { + opt(&lno) + } + eg, _ := errgroup.WithContext(ctx) b.nodes = make([]Node, len(b.NodeGroup.Nodes)) @@ -121,7 +140,7 @@ func (b *Builder) LoadNodes(ctx context.Context, withData bool) (_ []Node, err e node.Driver = d node.ImageOpt = imageopt - if withData { + if lno.data { if err := node.loadData(ctx); err != nil { node.Err = err } @@ -136,7 +155,7 @@ func (b *Builder) LoadNodes(ctx context.Context, withData bool) (_ []Node, err e } // TODO: This should be done in the routine loading driver data - if withData { + if lno.data { kubernetesDriverCount := 0 for _, d := range b.nodes { if d.DriverInfo != nil && len(d.DriverInfo.DynamicNodes) > 0 { diff --git a/commands/bake.go b/commands/bake.go index 4843233f14b..958b8299a40 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -114,7 +114,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com if err = updateLastActivity(dockerCli, b.NodeGroup); err != nil { return errors.Wrapf(err, "failed to update builder last activity time") } - nodes, err = b.LoadNodes(ctx, false) + nodes, err = b.LoadNodes(ctx) if err != nil { return err } diff --git a/commands/build.go b/commands/build.go index 278c67fda59..9238c9de661 100644 --- a/commands/build.go +++ b/commands/build.go @@ -252,7 +252,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) (err error) { if err != nil { return err } - _, err = b.LoadNodes(ctx, false) + _, err = b.LoadNodes(ctx) if err != nil { return err } diff --git a/commands/create.go b/commands/create.go index ccf56e105b8..874dccd5749 100644 --- a/commands/create.go +++ b/commands/create.go @@ -270,7 +270,7 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error { timeoutCtx, cancel := context.WithTimeout(ctx, 20*time.Second) defer cancel() - nodes, err := b.LoadNodes(timeoutCtx, true) + nodes, err := b.LoadNodes(timeoutCtx, builder.WithData()) if err != nil { return err } diff --git a/commands/diskusage.go b/commands/diskusage.go index 87ad8f8d9ca..dd25e3f3c0e 100644 --- a/commands/diskusage.go +++ b/commands/diskusage.go @@ -39,7 +39,7 @@ func runDiskUsage(dockerCli command.Cli, opts duOptions) error { return err } - nodes, err := b.LoadNodes(ctx, false) + nodes, err := b.LoadNodes(ctx) if err != nil { return err } diff --git a/commands/inspect.go b/commands/inspect.go index 6a2b71a2618..bae2ac6d658 100644 --- a/commands/inspect.go +++ b/commands/inspect.go @@ -40,7 +40,7 @@ func runInspect(dockerCli command.Cli, in inspectOptions) error { timeoutCtx, cancel := context.WithTimeout(ctx, 20*time.Second) defer cancel() - nodes, err := b.LoadNodes(timeoutCtx, true) + nodes, err := b.LoadNodes(timeoutCtx, builder.WithData()) if in.bootstrap { var ok bool ok, err = b.Boot(ctx) @@ -48,7 +48,7 @@ func runInspect(dockerCli command.Cli, in inspectOptions) error { return err } if ok { - nodes, err = b.LoadNodes(timeoutCtx, true) + nodes, err = b.LoadNodes(timeoutCtx, builder.WithData()) } } diff --git a/commands/ls.go b/commands/ls.go index 66eae51e5f8..c53e714c60d 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -49,7 +49,7 @@ func runLs(dockerCli command.Cli, in lsOptions) error { for _, b := range builders { func(b *builder.Builder) { eg.Go(func() error { - _, _ = b.LoadNodes(timeoutCtx, true) + _, _ = b.LoadNodes(timeoutCtx, builder.WithData()) return nil }) }(b) diff --git a/commands/prune.go b/commands/prune.go index 67df4b2a040..454b04a8c5e 100644 --- a/commands/prune.go +++ b/commands/prune.go @@ -60,7 +60,7 @@ func runPrune(dockerCli command.Cli, opts pruneOptions) error { return err } - nodes, err := b.LoadNodes(ctx, false) + nodes, err := b.LoadNodes(ctx) if err != nil { return err } diff --git a/commands/rm.go b/commands/rm.go index 9f30d6b5444..6b026c3d526 100644 --- a/commands/rm.go +++ b/commands/rm.go @@ -55,7 +55,7 @@ func runRm(dockerCli command.Cli, in rmOptions) error { return err } - nodes, err := b.LoadNodes(ctx, false) + nodes, err := b.LoadNodes(ctx) if err != nil { return err } @@ -139,7 +139,7 @@ func rmAllInactive(ctx context.Context, txn *store.Txn, dockerCli command.Cli, i for _, b := range builders { func(b *builder.Builder) { eg.Go(func() error { - nodes, err := b.LoadNodes(timeoutCtx, true) + nodes, err := b.LoadNodes(timeoutCtx, builder.WithData()) if err != nil { return errors.Wrapf(err, "cannot load %s", b.Name) } diff --git a/commands/stop.go b/commands/stop.go index 2af78c8948b..c91b8ad3920 100644 --- a/commands/stop.go +++ b/commands/stop.go @@ -25,7 +25,7 @@ func runStop(dockerCli command.Cli, in stopOptions) error { if err != nil { return err } - nodes, err := b.LoadNodes(ctx, false) + nodes, err := b.LoadNodes(ctx) if err != nil { return err } diff --git a/controller/build/build.go b/controller/build/build.go index 66276c1b224..2872b357d2e 100644 --- a/controller/build/build.go +++ b/controller/build/build.go @@ -171,7 +171,7 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build if err = updateLastActivity(dockerCli, b.NodeGroup); err != nil { return nil, nil, errors.Wrapf(err, "failed to update builder last activity time") } - nodes, err := b.LoadNodes(ctx, false) + nodes, err := b.LoadNodes(ctx) if err != nil { return nil, nil, err }