Define a Controllers and LeaderControllers on the server config (#3043)

Signed-off-by: Chris Kim <oats87g@gmail.com>
pull/3060/head
Chris Kim 4 years ago committed by GitHub
parent 8ace8975d2
commit 69f96d6225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,10 +37,17 @@ func Run(app *cli.Context) error {
if err := cmds.InitLogging(); err != nil {
return err
}
return run(app, &cmds.ServerConfig)
return run(app, &cmds.ServerConfig, server.CustomControllers{}, server.CustomControllers{})
}
func run(app *cli.Context, cfg *cmds.Server) error {
func RunWithControllers(app *cli.Context, leaderControllers server.CustomControllers, controllers server.CustomControllers) error {
if err := cmds.InitLogging(); err != nil {
return err
}
return run(app, &cmds.ServerConfig, leaderControllers, controllers)
}
func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomControllers, controllers server.CustomControllers) error {
var (
err error
)
@ -255,6 +262,9 @@ func run(app *cli.Context, cfg *cmds.Server) error {
serverConfig.StartupHooks = append(serverConfig.StartupHooks, cfg.StartupHooks...)
serverConfig.LeaderControllers = append(serverConfig.LeaderControllers, leaderControllers...)
serverConfig.Controllers = append(serverConfig.Controllers, controllers...)
// TLS config based on mozilla ssl-config generator
// https://ssl-config.mozilla.org/#server=golang&version=1.13.6&config=intermediate&guideline=5.4
// Need to disable the TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 Cipher for TLS1.2

@ -132,6 +132,12 @@ func runControllers(ctx context.Context, config *Config) error {
}
}
for _, controller := range config.Controllers {
if err := controller(ctx, sc); err != nil {
return errors.Wrap(err, "controller")
}
}
if err := sc.Start(ctx); err != nil {
return err
}
@ -140,6 +146,11 @@ func runControllers(ctx context.Context, config *Config) error {
if err := coreControllers(ctx, sc, config); err != nil {
panic(err)
}
for _, controller := range config.LeaderControllers {
if err := controller(ctx, sc); err != nil {
panic(errors.Wrap(err, "leader controller"))
}
}
if err := sc.Start(ctx); err != nil {
panic(err)
}

@ -7,10 +7,14 @@ import (
)
type Config struct {
DisableAgent bool
DisableServiceLB bool
ControlConfig config.Control
Rootless bool
SupervisorPort int
StartupHooks []func(context.Context, <-chan struct{}, string) error
DisableAgent bool
DisableServiceLB bool
ControlConfig config.Control
Rootless bool
SupervisorPort int
StartupHooks []func(context.Context, <-chan struct{}, string) error
LeaderControllers CustomControllers
Controllers CustomControllers
}
type CustomControllers []func(ctx context.Context, sc *Context) error

Loading…
Cancel
Save