Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker driver plugin #4844

Merged
merged 25 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9d8d3e1
docker: properly launch docker logger process
nickethier Nov 6, 2018
98b295d
docker: started work on porting docker driver to new plugin framework
nickethier Nov 6, 2018
c2d94dc
drivers: support recoverable errors in the plugin RPC layer
nickethier Nov 9, 2018
5c777a3
drivers/docker: more work porting tests from old driver plugin
nickethier Nov 9, 2018
9c154d7
drivers: added NodeResources to drivers.TaskConfig
nickethier Nov 12, 2018
902eb94
docker: finished porting tests
nickethier Nov 12, 2018
396f6ab
docker: implement recover task logic
nickethier Nov 12, 2018
37ed755
docker: move recoverable error proto to shared structs
nickethier Nov 14, 2018
3601e42
plugins/driver: remove NodeResources from task Resources and use Perc…
nickethier Nov 16, 2018
0c62b9a
docker: moved fingerprint code to it's own file
nickethier Nov 16, 2018
cf69895
task_runner: emit event on task exit with exit result details
nickethier Nov 16, 2018
7d09ae5
docker: remove call to global metrics instance
nickethier Nov 19, 2018
3468880
docker: remove global pull coordinator
nickethier Nov 19, 2018
455e754
Apply suggestions from code review
schmichael Nov 19, 2018
577d4a2
docker: group common config into blocks
nickethier Nov 20, 2018
d7631e3
docker: move volume driver options to seperate block
nickethier Nov 20, 2018
0462c8a
docker: remove container pointer from task handle
nickethier Nov 20, 2018
8ae8932
docker: fix tests
nickethier Nov 20, 2018
249dbff
docker: move config RPCs to config.go
nickethier Nov 20, 2018
fab76c6
docker: add default blocks for driver plugin config schema
nickethier Nov 20, 2018
2393f6a
docker: unexport new coordinator func
nickethier Nov 20, 2018
4dfcc80
task_runner: use task and alloc copies instead of referencing the ori…
nickethier Nov 20, 2018
6dfa230
task_runner: use NodeResources instead of deprecated struct
nickethier Nov 20, 2018
ace09b3
Apply suggestions from code review
schmichael Nov 21, 2018
fc53f5f
docker: sync access to exit result within a handle
nickethier Nov 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion client/allocrunner/taskrunner/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ MAIN:
select {
case result = <-resultCh:
// WaitCh returned a result
if result != nil {
tr.handleTaskExitResult(result)
}
case <-tr.ctx.Done():
// TaskRunner was told to exit immediately
return
Expand Down Expand Up @@ -410,6 +413,7 @@ MAIN:
event := structs.NewTaskEvent(structs.TaskTerminated).
SetExitCode(result.ExitCode).
SetSignal(result.Signal).
SetOOMKilled(result.OOMKilled).
SetExitMessage(result.Err)
tr.UpdateState(structs.TaskStateDead, event)
}
Expand All @@ -422,6 +426,20 @@ MAIN:
tr.logger.Debug("task run loop exiting")
}

func (tr *TaskRunner) handleTaskExitResult(result *drivers.ExitResult) {
event := structs.NewTaskEvent(structs.TaskTerminated).
SetExitCode(result.ExitCode).
SetSignal(result.Signal).
SetOOMKilled(result.OOMKilled).
SetExitMessage(result.Err)

tr.EmitEvent(event)

if !tr.clientConfig.DisableTaggedMetrics {
metrics.IncrCounterWithLabels([]string{"client", "allocs", "oom_killed"}, 1, tr.baseLabels)
}
}

// handleUpdates runs update hooks when triggerUpdateCh is ticked and exits
// when Run has returned. Should only be run in a goroutine from Run.
func (tr *TaskRunner) handleUpdates() {
Expand Down Expand Up @@ -650,12 +668,17 @@ func (tr *TaskRunner) persistLocalState() error {
// buildTaskConfig builds a drivers.TaskConfig with an unique ID for the task.
// The ID is consistently built from the alloc ID, task name and restart attempt.
func (tr *TaskRunner) buildTaskConfig() *drivers.TaskConfig {

return &drivers.TaskConfig{
ID: fmt.Sprintf("%s/%s/%d", tr.allocID, tr.taskName, tr.restartTracker.GetCount()),
Name: tr.task.Name,
Resources: &drivers.Resources{
NomadResources: tr.task.Resources,
//TODO Calculate the LinuxResources
LinuxResources: &drivers.LinuxResources{
MemoryLimitBytes: int64(tr.Task().Resources.MemoryMB) * 1024 * 1024,
CPUShares: int64(tr.Task().Resources.CPU),
PercentTicks: float64(tr.task.Resources.CPU) / float64(tr.clientConfig.Node.Resources.CPU),
nickethier marked this conversation as resolved.
Show resolved Hide resolved
},
schmichael marked this conversation as resolved.
Show resolved Hide resolved
},
Env: tr.envBuilder.Build().Map(),
User: tr.task.User,
Expand Down
6 changes: 6 additions & 0 deletions command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/hashicorp/nomad/command/agent"
"github.com/hashicorp/nomad/drivers/docker/docklog"
"github.com/hashicorp/nomad/version"
"github.com/mitchellh/cli"
)
Expand Down Expand Up @@ -210,6 +211,11 @@ func Commands(metaPtr *Meta, agentUi cli.Ui) map[string]cli.CommandFactory {
Meta: meta,
}, nil
},
docklog.PluginName: func() (cli.Command, error) {
nickethier marked this conversation as resolved.
Show resolved Hide resolved
return &DockerLoggerPluginCommand{
Meta: meta,
}, nil
},
"eval": func() (cli.Command, error) {
return &EvalCommand{
Meta: meta,
Expand Down
36 changes: 36 additions & 0 deletions command/docker_logger_plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package command

import (
"strings"

hclog "github.com/hashicorp/go-hclog"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/drivers/docker/docklog"
"github.com/hashicorp/nomad/plugins/base"
)

type DockerLoggerPluginCommand struct {
Meta
}

func (e *DockerLoggerPluginCommand) Help() string {
helpText := `
This is a command used by Nomad internally to launch the docker logger process"
`
return strings.TrimSpace(helpText)
}

func (e *DockerLoggerPluginCommand) Synopsis() string {
return "internal - launch a docker logger plugin"
}

func (e *DockerLoggerPluginCommand) Run(args []string) int {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: base.Handshake,
Plugins: map[string]plugin.Plugin{
docklog.PluginName: docklog.NewPlugin(docklog.NewDockerLogger(hclog.Default().Named(docklog.PluginName))),
},
GRPCServer: plugin.DefaultGRPCServer,
})
return 0
}
Loading