Skip to content

Commit

Permalink
Fix init DB conflict with multiple replicas
Browse files Browse the repository at this point in the history
Signed-off-by: astraw99 <wangchengiscool@gmail.com>
  • Loading branch information
astraw99 committed Aug 13, 2023
1 parent fa09afc commit 53fc80d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
21 changes: 14 additions & 7 deletions workflow/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ func (wfc *WorkflowController) updateConfig() error {
wfc.offloadNodeStatusRepo = sqldb.ExplosiveOffloadNodeStatusRepo
wfc.wfArchive = sqldb.NullWorkflowArchive
wfc.archiveLabelSelector = labels.Everything()

wfc.hydrator = hydrator.New(wfc.offloadNodeStatusRepo)
wfc.updateEstimatorFactory()
wfc.rateLimiter = wfc.newRateLimiter()

log.WithField("executorImage", wfc.executorImage()).
WithField("executorImagePullPolicy", wfc.executorImagePullPolicy()).
WithField("managedNamespace", wfc.GetManagedNamespace()).
Info()
return nil
}

// initDB inits argo DB tables
func (wfc *WorkflowController) initDB() error {
persistence := wfc.Config.Persistence
if persistence != nil {
log.Info("Persistence configuration enabled")
Expand Down Expand Up @@ -75,14 +89,7 @@ func (wfc *WorkflowController) updateConfig() error {
} else {
log.Info("Persistence configuration disabled")
}
wfc.hydrator = hydrator.New(wfc.offloadNodeStatusRepo)
wfc.updateEstimatorFactory()
wfc.rateLimiter = wfc.newRateLimiter()

log.WithField("executorImage", wfc.executorImage()).
WithField("executorImagePullPolicy", wfc.executorImagePullPolicy()).
WithField("managedNamespace", wfc.GetManagedNamespace()).
Info()
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions workflow/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ var indexers = cache.Indexers{
func (wfc *WorkflowController) Run(ctx context.Context, wfWorkers, workflowTTLWorkers, podCleanupWorkers, cronWorkflowWorkers int) {
defer runtimeutil.HandleCrash(runtimeutil.PanicHandlers...)

// init DB after leader election (if enabled)
if err := wfc.initDB(); err != nil {
log.Fatalf("Failed to init db: %v", err)
}

ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down

0 comments on commit 53fc80d

Please sign in to comment.