diff --git a/pkg/cli/cmds/server.go b/pkg/cli/cmds/server.go index fbd3c8d8b3f5..5746ac59d635 100644 --- a/pkg/cli/cmds/server.go +++ b/pkg/cli/cmds/server.go @@ -1,6 +1,9 @@ package cmds import ( + "context" + + "github.com/rancher/k3s/pkg/daemons/config" "github.com/rancher/k3s/pkg/version" "github.com/rancher/spur/cli" "github.com/rancher/spur/cli/altsrc" @@ -54,6 +57,7 @@ type Server struct { ClusterInit bool ClusterReset bool EncryptSecrets bool + StartupHooks []func(context.Context, config.Control) error } var ServerConfig Server diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index c911b7ed6eb1..058ad7abc4f7 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -193,6 +193,8 @@ func run(app *cli.Context, cfg *cmds.Server) error { return errors.Wrap(err, "Invalid tls-min-version") } + serverConfig.StartupHooks = append(serverConfig.StartupHooks, cfg.StartupHooks...) + // 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 diff --git a/pkg/server/server.go b/pkg/server/server.go index 7c397e647d92..12bb4a0cc263 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -60,6 +60,12 @@ func StartServer(ctx context.Context, config *Config) error { return errors.Wrap(err, "starting tls server") } + for _, hook := range config.StartupHooks { + if err := hook(ctx, config.ControlConfig); err != nil { + return errors.Wrap(err, "startup hook") + } + } + ip := net2.ParseIP(config.ControlConfig.BindAddress) if ip == nil { hostIP, err := net.ChooseHostInterface() diff --git a/pkg/server/types.go b/pkg/server/types.go index 9bcc2f36394d..69f96389e194 100644 --- a/pkg/server/types.go +++ b/pkg/server/types.go @@ -1,6 +1,8 @@ package server import ( + "context" + "github.com/rancher/k3s/pkg/daemons/config" ) @@ -10,4 +12,5 @@ type Config struct { ControlConfig config.Control Rootless bool SupervisorPort int + StartupHooks []func(context.Context, config.Control) error }