Skip to content

Commit

Permalink
fixing a case with no serialWorkers
Browse files Browse the repository at this point in the history
  • Loading branch information
networkop committed Jul 16, 2021
1 parent b2a8e51 commit b1818e4
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ func (c *CLab) GlobalRuntime() runtime.ContainerRuntime {
func (c *CLab) CreateNodes(ctx context.Context, maxWorkers uint, serialNodes map[string]struct{}) {

wg := new(sync.WaitGroup)
wg.Add(int(maxWorkers))
if len(serialNodes) > 0 {
wg.Add(1)
}

concurrentChan := make(chan nodes.Node)
serialChan := make(chan nodes.Node)
Expand Down Expand Up @@ -208,12 +204,18 @@ func (c *CLab) CreateNodes(ctx context.Context, maxWorkers uint, serialNodes map
}

// start concurrent workers
wg.Add(int(maxWorkers))
// it's safe to not check if all nodes are serial because in that case
// maxWorkers will be 0
for i := uint(0); i < maxWorkers; i++ {
go workerFunc(i, concurrentChan, wg)
}

// start the serial worker
go workerFunc(maxWorkers, serialChan, wg)
if len(serialNodes) > 0 {
wg.Add(1)
go workerFunc(maxWorkers, serialChan, wg)
}

// send nodes to workers
for _, n := range c.Nodes {
Expand Down Expand Up @@ -289,10 +291,6 @@ func (c *CLab) CreateLinks(ctx context.Context, workers uint, postdeploy bool) {
func (c *CLab) DeleteNodes(ctx context.Context, workers uint, deleteCandidates map[string]nodes.Node, serialNodes map[string]struct{}) {

wg := new(sync.WaitGroup)
wg.Add(int(workers))
if len(serialNodes) > 0 {
wg.Add(1)
}

concurrentChan := make(chan nodes.Node)
serialChan := make(chan nodes.Node)
Expand All @@ -317,12 +315,16 @@ func (c *CLab) DeleteNodes(ctx context.Context, workers uint, deleteCandidates m
}

// start concurrent workers
wg.Add(int(workers))
for i := uint(0); i < workers; i++ {
go workerFunc(i, concurrentChan, wg)
}

// start the serial worker
go workerFunc(workers, serialChan, wg)
if len(serialNodes) > 0 {
wg.Add(1)
go workerFunc(workers, serialChan, wg)
}

// send nodes to workers
for _, n := range c.Nodes {
Expand Down

0 comments on commit b1818e4

Please sign in to comment.