-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4757 from hashicorp/f-driver-plugin-loader
driver plugin loader
- Loading branch information
Showing
42 changed files
with
1,291 additions
and
751 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package taskrunner | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
cstructs "github.com/hashicorp/nomad/client/structs" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
"github.com/hashicorp/nomad/plugins/drivers" | ||
) | ||
|
||
// NewDriverHandle returns a handle for task operations on a specific task | ||
func NewDriverHandle(driver drivers.DriverPlugin, taskID string, task *structs.Task, net *cstructs.DriverNetwork) *DriverHandle { | ||
return &DriverHandle{ | ||
driver: driver, | ||
net: net, | ||
taskID: taskID, | ||
task: task, | ||
} | ||
} | ||
|
||
// DriverHandle encapsulates a driver plugin client and task identifier and exposes | ||
// an api to perform driver operations on the task | ||
type DriverHandle struct { | ||
driver drivers.DriverPlugin | ||
net *cstructs.DriverNetwork | ||
task *structs.Task | ||
taskID string | ||
} | ||
|
||
func (h *DriverHandle) ID() string { | ||
return h.taskID | ||
} | ||
|
||
func (h *DriverHandle) WaitCh(ctx context.Context) (<-chan *drivers.ExitResult, error) { | ||
return h.driver.WaitTask(ctx, h.taskID) | ||
} | ||
|
||
func (h *DriverHandle) Update(task *structs.Task) error { | ||
return nil | ||
} | ||
|
||
func (h *DriverHandle) Kill() error { | ||
return h.driver.StopTask(h.taskID, h.task.KillTimeout, h.task.KillSignal) | ||
} | ||
|
||
func (h *DriverHandle) Stats() (*cstructs.TaskResourceUsage, error) { | ||
return h.driver.TaskStats(h.taskID) | ||
} | ||
|
||
func (h *DriverHandle) Signal(s string) error { | ||
return h.driver.SignalTask(h.taskID, s) | ||
} | ||
|
||
func (h *DriverHandle) Exec(timeout time.Duration, cmd string, args []string) ([]byte, int, error) { | ||
command := append([]string{cmd}, args...) | ||
res, err := h.driver.ExecTask(h.taskID, command, timeout) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
return res.Stdout, res.ExitResult.ExitCode, res.ExitResult.Err | ||
} | ||
|
||
func (h *DriverHandle) Network() *cstructs.DriverNetwork { | ||
return h.net | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package interfaces | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
cstructs "github.com/hashicorp/nomad/client/structs" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
"github.com/hashicorp/nomad/plugins/drivers" | ||
) | ||
|
||
// DriverHandle wraps operations to a driver such that they are operated on a specific | ||
// task | ||
type DriverHandle interface { | ||
// ID returns the task ID | ||
ID() string | ||
|
||
// WaitCh is used to return a channel used to wait for task completion | ||
WaitCh(context.Context) (<-chan *drivers.ExitResult, error) | ||
|
||
// Update is used to update the task if possible and update task related | ||
// configurations. | ||
Update(task *structs.Task) error | ||
|
||
// Kill is used to stop the task | ||
Kill() error | ||
|
||
// Stats returns aggregated stats of the driver | ||
Stats() (*cstructs.TaskResourceUsage, error) | ||
|
||
// Signal is used to send a signal to the task | ||
Signal(s string) error | ||
|
||
// ScriptExecutor is an interface used to execute commands such as | ||
// health check scripts in the a DriverHandle's context. | ||
ScriptExecutor | ||
|
||
// Network returns the driver's network or nil if the driver did not | ||
// create a network. | ||
Network() *cstructs.DriverNetwork | ||
} | ||
|
||
// ScriptExecutor is an interface that supports Exec()ing commands in the | ||
// driver's context. Split out of DriverHandle to ease testing. | ||
type ScriptExecutor interface { | ||
Exec(timeout time.Duration, cmd string, args []string) ([]byte, int, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.