Skip to content

Commit

Permalink
builder: opt to set dial meta when loading nodes
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Oct 11, 2023
1 parent 3a80666 commit 417dbf8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions builder/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (b *Builder) Nodes() []Node {
type LoadNodesOption func(*loadNodesOptions)

type loadNodesOptions struct {
data bool
data bool
dialMeta map[string][]string
}

func WithData() LoadNodesOption {
Expand All @@ -54,6 +55,12 @@ func WithData() LoadNodesOption {
}
}

func WithDialMeta(dialMeta map[string][]string) LoadNodesOption {
return func(o *loadNodesOptions) {
o.dialMeta = dialMeta
}
}

// 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 @@ -141,7 +148,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.dialMeta); err != nil {
node.Err = err
}
}
Expand Down Expand Up @@ -192,7 +199,7 @@ func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []N
return b.nodes, nil
}

func (n *Node) loadData(ctx context.Context) error {
func (n *Node) loadData(ctx context.Context, dialMeta map[string][]string) error {
if n.Driver == nil {
return nil
}
Expand All @@ -204,7 +211,7 @@ func (n *Node) loadData(ctx context.Context) error {
n.DriverInfo = info

if n.DriverInfo.Status == driver.Running {
c, err := n.Driver.Client(ctx)
c, err := n.Driver.Client(ctx, driver.WithDialMeta(dialMeta))
if err != nil {
return err
}
Expand Down

0 comments on commit 417dbf8

Please sign in to comment.