Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Argo DB init conflict when deploy workflow-controller with multiple replicas #11177 #11569

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions workflow/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (wfc *WorkflowController) updateConfig() error {
wfc.offloadNodeStatusRepo = sqldb.ExplosiveOffloadNodeStatusRepo
wfc.wfArchive = sqldb.NullWorkflowArchive
wfc.archiveLabelSelector = labels.Everything()

persistence := wfc.Config.Persistence
if persistence != nil {
log.Info("Persistence configuration enabled")
Expand All @@ -40,14 +41,7 @@ func (wfc *WorkflowController) updateConfig() error {
return err
}
log.Info("Persistence Session created successfully")
if !persistence.SkipMigration {
err = sqldb.NewMigrate(session, persistence.GetClusterName(), tableName).Exec(context.Background())
if err != nil {
return err
}
} else {
log.Info("DB migration is disabled")
}

wfc.session = session
}
sqldb.ConfigureDBSession(wfc.session, persistence.ConnectionPool)
Expand Down Expand Up @@ -75,6 +69,7 @@ func (wfc *WorkflowController) updateConfig() error {
} else {
log.Info("Persistence configuration disabled")
}

wfc.hydrator = hydrator.New(wfc.offloadNodeStatusRepo)
wfc.updateEstimatorFactory()
wfc.rateLimiter = wfc.newRateLimiter()
Expand All @@ -86,6 +81,27 @@ func (wfc *WorkflowController) updateConfig() error {
return nil
}

// initDB inits argo DB tables
func (wfc *WorkflowController) initDB() error {
persistence := wfc.Config.Persistence
if persistence != nil {
tableName, err := sqldb.GetTableName(persistence)
if err != nil {
return err
}
if !persistence.SkipMigration {
err = sqldb.NewMigrate(wfc.session, persistence.GetClusterName(), tableName).Exec(context.Background())
astraw99 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
} else {
log.Info("DB migration is disabled")
}
}

return nil
}

func (wfc *WorkflowController) newRateLimiter() *rate.Limiter {
return rate.NewLimiter(rate.Limit(wfc.Config.GetResourceRateLimit().Limit), wfc.Config.GetResourceRateLimit().Burst)
}
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