Import upstream exec driver

This commit is contained in:
Alex 2022-11-28 12:26:41 +01:00
parent 8977e5122a
commit 06be7dcbf6
Signed by: lx
GPG Key ID: 0E496D15096376BE
4 changed files with 465 additions and 392 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
package hello package exec
import ( import (
"context" "context"
@ -6,30 +6,26 @@ import (
"sync" "sync"
"time" "time"
"github.com/hashicorp/go-hclog" hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin" plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers"
) )
// taskHandle should store all relevant runtime information
// such as process ID if this is a local task or other meta
// data if this driver deals with external APIs
type taskHandle struct { type taskHandle struct {
exec executor.Executor
pid int
pluginClient *plugin.Client
logger hclog.Logger
// stateLock syncs access to all fields below // stateLock syncs access to all fields below
stateLock sync.RWMutex stateLock sync.RWMutex
logger hclog.Logger taskConfig *drivers.TaskConfig
exec executor.Executor procState drivers.TaskState
pluginClient *plugin.Client startedAt time.Time
taskConfig *drivers.TaskConfig completedAt time.Time
procState drivers.TaskState exitResult *drivers.ExitResult
startedAt time.Time
completedAt time.Time
exitResult *drivers.ExitResult
// TODO: add any extra relevant information about the task.
pid int
} }
func (h *taskHandle) TaskStatus() *drivers.TaskStatus { func (h *taskHandle) TaskStatus() *drivers.TaskStatus {
@ -62,8 +58,9 @@ func (h *taskHandle) run() {
} }
h.stateLock.Unlock() h.stateLock.Unlock()
// TODO: wait for your task to complete and upate its state. // Block until process exits
ps, err := h.exec.Wait(context.Background()) ps, err := h.exec.Wait(context.Background())
h.stateLock.Lock() h.stateLock.Lock()
defer h.stateLock.Unlock() defer h.stateLock.Unlock()
@ -77,4 +74,6 @@ func (h *taskHandle) run() {
h.exitResult.ExitCode = ps.ExitCode h.exitResult.ExitCode = ps.ExitCode
h.exitResult.Signal = ps.Signal h.exitResult.Signal = ps.Signal
h.completedAt = ps.Time h.completedAt = ps.Time
// TODO: detect if the task OOMed
} }

7
exec2/pull-upstream.sh Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
REF=v1.4.3
wget https://github.com/hashicorp/nomad/raw/${REF}/drivers/exec/driver.go -O driver.go
wget https://github.com/hashicorp/nomad/raw/${REF}/drivers/exec/handle.go -O handle.go
wget https://github.com/hashicorp/nomad/raw/${REF}/drivers/exec/state.go -O state.go

View File

@ -1,12 +1,9 @@
package hello package exec
import ( import (
"sync" "sync"
) )
// taskStore provides a mechanism to store and retrieve
// task handles given a string identifier. The ID should
// be unique per task
type taskStore struct { type taskStore struct {
store map[string]*taskHandle store map[string]*taskHandle
lock sync.RWMutex lock sync.RWMutex