Skip to content

Commit

Permalink
driver: allow arbitrary client opts
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jul 4, 2024
1 parent b96ad59 commit 1dceb49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions builder/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions driver/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1dceb49

Please sign in to comment.