ar: plumb error handling into alloc runner hook initialization

This commit is contained in:
Nick Ethier
2019-05-08 13:45:20 -04:00
parent 16343ae23a
commit 35de444e9b
4 changed files with 12 additions and 6 deletions

View File

@@ -185,7 +185,9 @@ func NewAllocRunner(config *Config) (*allocRunner, error) {
ar.allocDir = allocdir.NewAllocDir(ar.logger, filepath.Join(config.ClientConfig.AllocDir, alloc.ID))
// Initialize the runners hooks.
ar.initRunnerHooks()
if err := ar.initRunnerHooks(); err != nil {
return nil, err
}
// Create the TaskRunners
if err := ar.initTaskRunners(tg.Tasks); err != nil {

View File

@@ -94,7 +94,7 @@ func (a *allocHealthSetter) SetHealth(healthy, isDeploy bool, trackerTaskEvents
}
// initRunnerHooks intializes the runners hooks.
func (ar *allocRunner) initRunnerHooks() {
func (ar *allocRunner) initRunnerHooks() error {
hookLogger := ar.logger.Named("runner_hook")
// create health setting shim
@@ -110,7 +110,7 @@ func (ar *allocRunner) initRunnerHooks() {
}
// initialize platform specific hooks
ar.initPlatformRunnerHooks(hookLogger)
return ar.initPlatformRunnerHooks(hookLogger)
}
// prerun is used to run the runners prerun hooks.

View File

@@ -11,13 +11,17 @@ import (
)
// initialize linux specific alloc runner hooks
func (ar *allocRunner) initPlatformRunnerHooks(hookLogger hclog.Logger) {
func (ar *allocRunner) initPlatformRunnerHooks(hookLogger hclog.Logger) error {
// determine how the network must be created
ns := &allocNetworkIsolationSetter{ar: ar}
nm, _ := ar.initNetworkManager()
nm, err := ar.initNetworkManager()
if err != nil {
return err
}
ar.runnerHooks = append(ar.runnerHooks, newNetworkHook(ns, hookLogger, ar.Alloc(), nm))
return nil
}
func (ar *allocRunner) initNetworkManager() (nm drivers.DriverNetworkManager, err error) {

View File

@@ -5,4 +5,4 @@ package allocrunner
import hclog "github.com/hashicorp/go-hclog"
// noop for non linux clients
func (ar *allocRunner) initPlatformRunnerHooks(hookLogger hclog.Logger) {}
func (ar *allocRunner) initPlatformRunnerHooks(hookLogger hclog.Logger) error { return nil }