Skip to content

Commit

Permalink
Define a Controllers and LeaderControllers on the server config (#3053)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Kim <[email protected]>
  • Loading branch information
Oats87 authored Mar 12, 2021
1 parent 36b8c9f commit bc400f5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
14 changes: 12 additions & 2 deletions pkg/cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,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
)
Expand Down Expand Up @@ -233,6 +240,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
Expand Down
11 changes: 11 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,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
}
Expand All @@ -139,6 +145,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)
}
Expand Down
16 changes: 10 additions & 6 deletions pkg/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bc400f5

Please sign in to comment.