diff --git a/client/allocrunner/alloc_runner.go b/client/allocrunner/alloc_runner.go index 4cdf4ee00..cd43318c1 100644 --- a/client/allocrunner/alloc_runner.go +++ b/client/allocrunner/alloc_runner.go @@ -158,6 +158,15 @@ type allocRunner struct { serversContactedCh chan struct{} taskHookCoordinator *taskHookCoordinator + + // rpcClient is the RPC Client that should be used by the allocrunner and its + // hooks to communicate with Nomad Servers. + rpcClient RPCer +} + +// RPCer is the interface needed by hooks to make RPC calls. +type RPCer interface { + RPC(method string, args interface{}, reply interface{}) error } // NewAllocRunner returns a new allocation runner. @@ -193,6 +202,7 @@ func NewAllocRunner(config *Config) (*allocRunner, error) { devicemanager: config.DeviceManager, driverManager: config.DriverManager, serversContactedCh: config.ServersContactedCh, + rpcClient: config.RPCClient, } // Create the logger based on the allocation ID diff --git a/client/allocrunner/alloc_runner_hooks.go b/client/allocrunner/alloc_runner_hooks.go index 793ec530b..d37dd1dff 100644 --- a/client/allocrunner/alloc_runner_hooks.go +++ b/client/allocrunner/alloc_runner_hooks.go @@ -134,7 +134,7 @@ func (ar *allocRunner) initRunnerHooks(config *clientconfig.Config) error { logger: hookLogger, }), newConsulSockHook(hookLogger, alloc, ar.allocDir, config.ConsulConfig), - newCSIHook(hookLogger, alloc), + newCSIHook(hookLogger, alloc, ar.rpcClient), } return nil diff --git a/client/allocrunner/config.go b/client/allocrunner/config.go index 257d8db69..8eb013ede 100644 --- a/client/allocrunner/config.go +++ b/client/allocrunner/config.go @@ -68,4 +68,8 @@ type Config struct { // ServersContactedCh is closed when the first GetClientAllocs call to // servers succeeds and allocs are synced. ServersContactedCh chan struct{} + + // RPCClient is the RPC Client that should be used by the allocrunner and its + // hooks to communicate with Nomad Servers. + RPCClient RPCer } diff --git a/client/allocrunner/csi_hook.go b/client/allocrunner/csi_hook.go index cccd66397..edb427398 100644 --- a/client/allocrunner/csi_hook.go +++ b/client/allocrunner/csi_hook.go @@ -10,8 +10,9 @@ import ( // // It is a noop for allocs that do not depend on CSI Volumes. type csiHook struct { - alloc *structs.Allocation - logger hclog.Logger + alloc *structs.Allocation + logger hclog.Logger + rpcClient RPCer } func (c *csiHook) Name() string { @@ -27,10 +28,11 @@ func (c *csiHook) Prerun() error { return nil } -func newCSIHook(logger hclog.Logger, alloc *structs.Allocation) *csiHook { +func newCSIHook(logger hclog.Logger, alloc *structs.Allocation, rpcClient RPCer) *csiHook { return &csiHook{ - alloc: alloc, - logger: logger.Named("csi_hook"), + alloc: alloc, + logger: logger.Named("csi_hook"), + rpcClient: rpcClient, } } diff --git a/client/client.go b/client/client.go index fae2b2928..05ce5dd6a 100644 --- a/client/client.go +++ b/client/client.go @@ -1088,6 +1088,7 @@ func (c *Client) restoreState() error { DeviceManager: c.devicemanager, DriverManager: c.drivermanager, ServersContactedCh: c.serversContactedCh, + RPCClient: c, } c.configLock.RUnlock() @@ -2351,6 +2352,7 @@ func (c *Client) addAlloc(alloc *structs.Allocation, migrateToken string) error CSIManager: c.csimanager, DeviceManager: c.devicemanager, DriverManager: c.drivermanager, + RPCClient: c, } c.configLock.RUnlock()