driver: allow arbitrary client opts

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2024-07-04 11:32:26 +02:00
parent b96ad59f64
commit 1dceb49a27
No known key found for this signature in database
GPG Key ID: ADE44D8C9D44FBE4
2 changed files with 14 additions and 7 deletions

View File

@ -48,8 +48,9 @@ func (b *Builder) Nodes() []Node {
type LoadNodesOption func(*loadNodesOptions) type LoadNodesOption func(*loadNodesOptions)
type loadNodesOptions struct { type loadNodesOptions struct {
data bool data bool
dialMeta map[string][]string dialMeta map[string][]string
clientOpt []client.ClientOpt
} }
func WithData() LoadNodesOption { 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. // 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. // 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) { 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 node.ImageOpt = imageopt
if lno.data { if lno.data {
if err := node.loadData(ctx); err != nil { if err := node.loadData(ctx, lno.clientOpt...); err != nil {
node.Err = err 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 { if n.Driver == nil {
return nil return nil
} }
@ -257,7 +264,7 @@ func (n *Node) loadData(ctx context.Context) error {
} }
n.DriverInfo = info n.DriverInfo = info
if n.DriverInfo.Status == driver.Running { if n.DriverInfo.Status == driver.Running {
driverClient, err := n.Driver.Client(ctx) driverClient, err := n.Driver.Client(ctx, clientOpt...)
if err != nil { if err != nil {
return err return err
} }

View File

@ -155,9 +155,9 @@ type DriverHandle struct {
historyAPISupported bool 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.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 return d.client, d.err
} }