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 (
"context"
@ -6,30 +6,26 @@ import (
"sync"
"time"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
hclog "github.com/hashicorp/go-hclog"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/drivers/shared/executor"
"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 {
exec executor.Executor
pid int
pluginClient *plugin.Client
logger hclog.Logger
// stateLock syncs access to all fields below
stateLock sync.RWMutex
logger hclog.Logger
exec executor.Executor
pluginClient *plugin.Client
taskConfig *drivers.TaskConfig
procState drivers.TaskState
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 {
@ -62,8 +58,9 @@ func (h *taskHandle) run() {
}
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())
h.stateLock.Lock()
defer h.stateLock.Unlock()
@ -77,4 +74,6 @@ func (h *taskHandle) run() {
h.exitResult.ExitCode = ps.ExitCode
h.exitResult.Signal = ps.Signal
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 (
"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 {
store map[string]*taskHandle
lock sync.RWMutex