mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
client: Pass an RPC Client to AllocRunners
As part of introducing support for CSI, AllocRunner hooks need to be able to communicate with Nomad Servers for validation of and interaction with storage volumes. Here we create a small RPCer interface and pass the client (rpc client) to the AR in preparation for making these RPCs.
This commit is contained in:
committed by
Tim Gross
parent
27da32ce2a
commit
69cbb964e1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user