Skip to content

Commit

Permalink
allocrunner: provide factory function so we can build mock ARs (#17161)
Browse files Browse the repository at this point in the history
Tools like `nomad-nodesim` are unable to implement a minimal implementation of
an allocrunner so that we can test the client communication without having to
lug around the entire allocrunner/taskrunner code base. The allocrunner was
implemented with an interface specifically for this purpose, but there were
circular imports that made it challenging to use in practice.

Move the AllocRunner interface into an inner package and provide a factory
function type. Provide a minimal test that exercises the new function so that
consumers have some idea of what the minimum implementation required is.
  • Loading branch information
tgross authored May 12, 2023
1 parent f2e603d commit 88323ba
Show file tree
Hide file tree
Showing 23 changed files with 501 additions and 302 deletions.
14 changes: 4 additions & 10 deletions client/allocrunner/alloc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/hashicorp/nomad/client/allocrunner/state"
"github.com/hashicorp/nomad/client/allocrunner/tasklifecycle"
"github.com/hashicorp/nomad/client/allocrunner/taskrunner"
"github.com/hashicorp/nomad/client/allocwatcher"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/consul"
"github.com/hashicorp/nomad/client/devicemanager"
Expand Down Expand Up @@ -152,10 +151,10 @@ type allocRunner struct {

// prevAllocWatcher allows waiting for any previous or preempted allocations
// to exit
prevAllocWatcher allocwatcher.PrevAllocWatcher
prevAllocWatcher config.PrevAllocWatcher

// prevAllocMigrator allows the migration of a previous allocations alloc dir.
prevAllocMigrator allocwatcher.PrevAllocMigrator
prevAllocMigrator config.PrevAllocMigrator

// dynamicRegistry contains all locally registered dynamic plugins (e.g csi
// plugins).
Expand Down Expand Up @@ -190,7 +189,7 @@ type allocRunner struct {

// rpcClient is the RPC Client that should be used by the allocrunner and its
// hooks to communicate with Nomad Servers.
rpcClient RPCer
rpcClient config.RPCer

// serviceRegWrapper is the handler wrapper that is used by service hooks
// to perform service and check registration and deregistration.
Expand All @@ -203,13 +202,8 @@ type allocRunner struct {
getter cinterfaces.ArtifactGetter
}

// 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.
func NewAllocRunner(config *Config) (*allocRunner, error) {
func NewAllocRunner(config *config.AllocRunnerConfig) (interfaces.AllocRunner, error) {
alloc := config.Alloc
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
if tg == nil {
Expand Down
Loading

0 comments on commit 88323ba

Please sign in to comment.