Skip to content

Commit

Permalink
enter the creation phase in the worker func to keep it consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Feb 10, 2024
1 parent 0332ffa commit 583d3b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
16 changes: 7 additions & 9 deletions clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,6 @@ func (c *CLab) scheduleNodes(ctx context.Context, maxWorkers int, skipPostDeploy
time.Sleep(time.Duration(delay) * time.Second)
}

// No need to EnterPhase for WaitForCreate
// since it is called externally already.

// Pre-deploy stage
err := node.PreDeploy(
ctx,
Expand All @@ -538,6 +535,12 @@ func (c *CLab) scheduleNodes(ctx context.Context, maxWorkers int, skipPostDeploy
continue
}

// enter the create phase
err = dm.EnterPhase(node.Config().ShortName, types.WaitForCreate)
if err != nil {
log.Error(err)
}

// Deploy
err = node.Deploy(ctx, &nodes.DeployParams{})
if err != nil {
Expand Down Expand Up @@ -661,7 +664,7 @@ func (c *CLab) scheduleNodes(ctx context.Context, maxWorkers int, skipPostDeploy
go workerFunc(i, concurrentChan, wg, c.dependencyManager)
}

// Waitgroup used to protect the channel towards the workers of being closed to early
// Waitgroup protects the channel towards the workers of being closed too early
workerFuncChWG := new(sync.WaitGroup)

// schedule nodes via a go func to create links in parallel
Expand All @@ -673,11 +676,6 @@ func (c *CLab) scheduleNodes(ctx context.Context, maxWorkers int, skipPostDeploy
go func(node nodes.Node, dm depMgr.DependencyManager,
workerChan chan<- nodes.Node, wfcwg *sync.WaitGroup,
) {
// wait for all the nodes that node depends on
err := dm.EnterPhase(node.Config().ShortName, types.WaitForCreate)
if err != nil {
log.Error(err)
}
// wait for possible external dependencies
c.WaitForExternalNodeDependencies(ctx, node.Config().ShortName)
// when all nodes that this node depends on are created, push it into the channel
Expand Down
36 changes: 18 additions & 18 deletions mocks/dependency_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 583d3b6

Please sign in to comment.