This commit is contained in:
Alex 2022-11-29 09:51:18 +01:00
parent 14bd8f2010
commit b0c7108d0d
Signed by: lx
GPG key ID: 0E496D15096376BE
2 changed files with 27 additions and 27 deletions

View file

@ -8,12 +8,12 @@ import (
"sync" "sync"
"time" "time"
"github.com/Alexis211/nomad-driver-exec2/executor"
"github.com/hashicorp/consul-template/signals" "github.com/hashicorp/consul-template/signals"
hclog "github.com/hashicorp/go-hclog" hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/lib/cgutil" "github.com/hashicorp/nomad/client/lib/cgutil"
"github.com/hashicorp/nomad/drivers/shared/capabilities" "github.com/hashicorp/nomad/drivers/shared/capabilities"
"github.com/hashicorp/nomad/drivers/shared/eventer" "github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/Alexis211/nomad-driver-exec2/executor"
"github.com/hashicorp/nomad/drivers/shared/resolvconf" "github.com/hashicorp/nomad/drivers/shared/resolvconf"
"github.com/hashicorp/nomad/helper/pluginutils/hclutils" "github.com/hashicorp/nomad/helper/pluginutils/hclutils"
"github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/helper/pluginutils/loader"
@ -244,9 +244,9 @@ func (tc *TaskConfig) validate() error {
// StartTask. This information is needed to rebuild the task state and handler // StartTask. This information is needed to rebuild the task state and handler
// during recovery. // during recovery.
type TaskState struct { type TaskState struct {
TaskConfig *drivers.TaskConfig TaskConfig *drivers.TaskConfig
Pid int Pid int
StartedAt time.Time StartedAt time.Time
} }
// NewPlugin returns a new DrivePlugin implementation // NewPlugin returns a new DrivePlugin implementation
@ -409,16 +409,16 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
// Create new executor // Create new executor
exec := executor.NewExecutorWithIsolation( exec := executor.NewExecutorWithIsolation(
d.logger.With("task_name", handle.Config.Name, "alloc_id", handle.Config.AllocID),) d.logger.With("task_name", handle.Config.Name, "alloc_id", handle.Config.AllocID))
h := &taskHandle{ h := &taskHandle{
exec: exec, exec: exec,
pid: taskState.Pid, pid: taskState.Pid,
taskConfig: taskState.TaskConfig, taskConfig: taskState.TaskConfig,
procState: drivers.TaskStateRunning, procState: drivers.TaskStateRunning,
startedAt: taskState.StartedAt, startedAt: taskState.StartedAt,
exitResult: &drivers.ExitResult{}, exitResult: &drivers.ExitResult{},
logger: d.logger, logger: d.logger,
} }
d.tasks.Set(taskState.TaskConfig.ID, h) d.tasks.Set(taskState.TaskConfig.ID, h)
@ -446,7 +446,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
handle.Config = cfg handle.Config = cfg
exec := executor.NewExecutorWithIsolation( exec := executor.NewExecutorWithIsolation(
d.logger.With("task_name", handle.Config.Name, "alloc_id", handle.Config.AllocID),) d.logger.With("task_name", handle.Config.Name, "alloc_id", handle.Config.AllocID))
user := cfg.User user := cfg.User
if user == "" { if user == "" {
@ -548,18 +548,18 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
} }
h := &taskHandle{ h := &taskHandle{
exec: exec, exec: exec,
pid: ps.Pid, pid: ps.Pid,
taskConfig: cfg, taskConfig: cfg,
procState: drivers.TaskStateRunning, procState: drivers.TaskStateRunning,
startedAt: time.Now().Round(time.Millisecond), startedAt: time.Now().Round(time.Millisecond),
logger: d.logger, logger: d.logger,
} }
driverState := TaskState{ driverState := TaskState{
Pid: ps.Pid, Pid: ps.Pid,
TaskConfig: cfg, TaskConfig: cfg,
StartedAt: h.startedAt, StartedAt: h.startedAt,
} }
if err := handle.SetDriverState(&driverState); err != nil { if err := handle.SetDriverState(&driverState); err != nil {

View file

@ -6,15 +6,15 @@ import (
"sync" "sync"
"time" "time"
hclog "github.com/hashicorp/go-hclog"
"github.com/Alexis211/nomad-driver-exec2/executor" "github.com/Alexis211/nomad-driver-exec2/executor"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers"
) )
type taskHandle struct { type taskHandle struct {
exec executor.Executor exec executor.Executor
pid int pid int
logger hclog.Logger logger hclog.Logger
// stateLock syncs access to all fields below // stateLock syncs access to all fields below
stateLock sync.RWMutex stateLock sync.RWMutex