add ctx to hook, handle hook errors

Signed-off-by: Brian Downs <brian.downs@gmail.com>
This commit is contained in:
Brian Downs 2020-08-19 16:54:58 -07:00
parent fa2c1422b3
commit 324bb55986
3 changed files with 9 additions and 3 deletions

View File

@ -1,6 +1,8 @@
package cmds
import (
"context"
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/version"
"github.com/rancher/spur/cli"
@ -55,7 +57,7 @@ type Server struct {
ClusterInit bool
ClusterReset bool
EncryptSecrets bool
StartupHooks []func(config.Control) error
StartupHooks []func(context.Context, config.Control) error
}
var ServerConfig Server

View File

@ -61,7 +61,9 @@ func StartServer(ctx context.Context, config *Config) error {
}
for _, hook := range config.StartupHooks {
hook(config.ControlConfig)
if err := hook(ctx, config.ControlConfig); err != nil {
return errors.Wrap(err, "startup hook")
}
}
ip := net2.ParseIP(config.ControlConfig.BindAddress)

View File

@ -1,6 +1,8 @@
package server
import (
"context"
"github.com/rancher/k3s/pkg/daemons/config"
)
@ -10,5 +12,5 @@ type Config struct {
ControlConfig config.Control
Rootless bool
SupervisorPort int
StartupHooks []func(config.Control) error
StartupHooks []func(context.Context, config.Control) error
}