Unverified Commit 64017c52 authored by Chris Kim's avatar Chris Kim Committed by GitHub

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

Signed-off-by: 's avatarChris Kim <oats87g@gmail.com>
parent f6217608
...@@ -41,10 +41,17 @@ func Run(app *cli.Context) error { ...@@ -41,10 +41,17 @@ func Run(app *cli.Context) error {
if err := cmds.InitLogging(); err != nil { if err := cmds.InitLogging(); err != nil {
return err 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 ( var (
err error err error
) )
...@@ -226,6 +233,9 @@ func run(app *cli.Context, cfg *cmds.Server) error { ...@@ -226,6 +233,9 @@ func run(app *cli.Context, cfg *cmds.Server) error {
serverConfig.StartupHooks = append(serverConfig.StartupHooks, cfg.StartupHooks...) 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 // TLS config based on mozilla ssl-config generator
// https://ssl-config.mozilla.org/#server=golang&version=1.13.6&config=intermediate&guideline=5.4 // 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 // Need to disable the TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 Cipher for TLS1.2
......
...@@ -138,6 +138,12 @@ func runControllers(ctx context.Context, config *Config) error { ...@@ -138,6 +138,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 { if err := sc.Start(ctx); err != nil {
return err return err
} }
...@@ -146,6 +152,11 @@ func runControllers(ctx context.Context, config *Config) error { ...@@ -146,6 +152,11 @@ func runControllers(ctx context.Context, config *Config) error {
if err := masterControllers(ctx, sc, config); err != nil { if err := masterControllers(ctx, sc, config); err != nil {
panic(err) 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 { if err := sc.Start(ctx); err != nil {
panic(err) panic(err)
} }
......
...@@ -13,4 +13,8 @@ type Config struct { ...@@ -13,4 +13,8 @@ type Config struct {
Rootless bool Rootless bool
SupervisorPort int SupervisorPort int
StartupHooks []func(context.Context, <-chan struct{}, string) error StartupHooks []func(context.Context, <-chan struct{}, string) error
LeaderControllers CustomControllers
Controllers CustomControllers
} }
type CustomControllers []func(ctx context.Context, sc *Context) error
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment