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

Feat: support exit-on-lost-leader flag #868

Merged
merged 1 commit into from
Aug 8, 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
7 changes: 6 additions & 1 deletion pkg/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
PluginConfig PluginConfig

DexServerURL string

// ExitOnLostLeader will exit the process if this server lost the leader election, set this to true for debugging
ExitOnLostLeader bool
}

// PluginConfig the plugin directory config
Expand Down Expand Up @@ -95,7 +98,8 @@
CorePluginPath: "core-plugins",
CustomPluginPath: []string{"plugins"},
},
DexServerURL: "http://dex.vela-system:5556",
DexServerURL: "http://dex.vela-system:5556",
ExitOnLostLeader: true,

Check warning on line 102 in pkg/server/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config/config.go#L101-L102

Added lines #L101 - L102 were not covered by tests
}
}

Expand Down Expand Up @@ -127,5 +131,6 @@
fs.StringVar(&s.WorkflowVersion, "workflow-version", c.WorkflowVersion, "the version of workflow to meet controller requirement.")
fs.StringVar(&s.DexServerURL, "dex-server", c.DexServerURL, "the URL of the dex server.")
fs.StringArrayVar(&s.PluginConfig.CustomPluginPath, "plugin-path", c.PluginConfig.CustomPluginPath, "the path of the plugin directory")
fs.BoolVar(&s.ExitOnLostLeader, "exit-on-lost-leader", c.ExitOnLostLeader, "exit the process if this server lost the leader election")

Check warning on line 134 in pkg/server/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config/config.go#L134

Added line #L134 was not covered by tests
profiling.AddFlags(fs)
}
2 changes: 1 addition & 1 deletion pkg/server/domain/service/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@
record.Finished = "true"
record.Status = model.RevisionStatusFail
if err := w.Store.Put(ctx, record); err != nil {
return fmt.Errorf(("failed to set the record status to terminated: %s"), err.Error())
return fmt.Errorf("failed to set the record status to terminated: %s", err.Error())

Check warning on line 448 in pkg/server/domain/service/workflow.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/domain/service/workflow.go#L448

Added line #L448 was not covered by tests
}
return bcode.ErrApplicationRevisionNotExist
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/server/event/sync/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ func (a *ApplicationSync) Start(ctx context.Context, errorChan chan error) {
}
app := item.(*v1beta1.Application)
if err := cu.AddOrUpdate(ctx, app); err != nil {
klog.Errorf("fail to add or update application %s: %s", app.Name, err.Error())
failTimes := a.Queue.NumRequeues(app)
klog.Errorf("fail to add or update application %s: %s, requeue times: %d", app.Name, err.Error(), failTimes)
if failTimes < 5 {
a.Queue.AddRateLimited(app)
} else {
klog.Errorf("fail to add or update application %s: %s, requeue times reach the limit(%d), give up", app.Name, err.Error(), failTimes)
a.Queue.Forget(app)
}
}
a.Queue.Done(app)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@
go event.StartEventWorker(ctx, errChan)
},
OnStoppedLeading: func() {
errChan <- fmt.Errorf("leader lost %s", s.cfg.LeaderConfig.ID)
if s.cfg.ExitOnLostLeader {
errChan <- fmt.Errorf("leader lost %s", s.cfg.LeaderConfig.ID)
}

Check warning on line 258 in pkg/server/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/server.go#L256-L258

Added lines #L256 - L258 were not covered by tests
},
OnNewLeader: func(identity string) {
if identity == s.cfg.LeaderConfig.ID {
Expand Down
Loading