diff --git a/builder/node.go b/builder/node.go index e1a02cca461..271b488b867 100644 --- a/builder/node.go +++ b/builder/node.go @@ -48,8 +48,9 @@ func (b *Builder) Nodes() []Node { type LoadNodesOption func(*loadNodesOptions) type loadNodesOptions struct { - data bool - dialMeta map[string][]string + data bool + dialMeta map[string][]string + clientOpt []client.ClientOpt } func WithData() LoadNodesOption { @@ -64,6 +65,12 @@ func WithDialMeta(dialMeta map[string][]string) LoadNodesOption { } } +func WithClientOpt(clientOpt ...client.ClientOpt) LoadNodesOption { + return func(o *loadNodesOptions) { + o.clientOpt = clientOpt + } +} + // 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, opts ...LoadNodesOption) (_ []Node, err error) { @@ -151,7 +158,7 @@ func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []N node.ImageOpt = imageopt if lno.data { - if err := node.loadData(ctx); err != nil { + if err := node.loadData(ctx, lno.clientOpt...); err != nil { node.Err = err } } @@ -247,7 +254,7 @@ func (n *Node) MarshalJSON() ([]byte, error) { }) } -func (n *Node) loadData(ctx context.Context) error { +func (n *Node) loadData(ctx context.Context, clientOpt ...client.ClientOpt) error { if n.Driver == nil { return nil } @@ -257,7 +264,7 @@ func (n *Node) loadData(ctx context.Context) error { } n.DriverInfo = info if n.DriverInfo.Status == driver.Running { - driverClient, err := n.Driver.Client(ctx) + driverClient, err := n.Driver.Client(ctx, clientOpt...) if err != nil { return err } diff --git a/driver/manager.go b/driver/manager.go index 746fd8f2f8d..509db1ca711 100644 --- a/driver/manager.go +++ b/driver/manager.go @@ -155,9 +155,9 @@ type DriverHandle struct { historyAPISupported bool } -func (d *DriverHandle) Client(ctx context.Context) (*client.Client, error) { +func (d *DriverHandle) Client(ctx context.Context, opt ...client.ClientOpt) (*client.Client, error) { d.once.Do(func() { - d.client, d.err = d.Driver.Client(ctx, d.getClientOptions()...) + d.client, d.err = d.Driver.Client(ctx, append(d.getClientOptions(), opt...)...) }) return d.client, d.err }