builder: use variadic options in LoadNodes func

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-08-22 22:11:50 +02:00
parent 5836c24e7d
commit fd251d2a7b
11 changed files with 34 additions and 15 deletions

View File

@ -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 {