2588b3bc98
This fixes few cases where driver eventor goroutines are leaked during normal operations, but especially so in tests. This change makes few modifications: First, it switches drivers to use `Context`s to manage shutdown events. Previously, it relied on callers invoking `.Shutdown()` function that is specific to internal drivers only and require casting. Using `Contexts` provide a consistent idiomatic way to manage lifecycle for both internal and external drivers. Also, I discovered few places where we don't clean up a temporary driver instance in the plugin catalog code, where we dispense a driver to inspect and validate the schema config without properly cleaning it up.
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
// This package provides a mechanism to build the Docker driver plugin as an
|
|
// external binary. The binary has two entry points; the docker driver and the
|
|
// docker plugin's logging child binary. An example of using this is `go build
|
|
// -o </nomad/plugin/dir/docker`. When Nomad agent is then launched, the
|
|
// external docker plugin will be used.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
log "github.com/hashicorp/go-hclog"
|
|
plugin "github.com/hashicorp/go-plugin"
|
|
"github.com/hashicorp/nomad/drivers/docker"
|
|
"github.com/hashicorp/nomad/drivers/docker/docklog"
|
|
"github.com/hashicorp/nomad/plugins"
|
|
"github.com/hashicorp/nomad/plugins/base"
|
|
)
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) > 1 {
|
|
// Detect if we are being launched as a docker logging plugin
|
|
switch os.Args[1] {
|
|
case docklog.PluginName:
|
|
logger := log.New(&log.LoggerOptions{
|
|
Level: log.Trace,
|
|
JSONFormat: true,
|
|
Name: docklog.PluginName,
|
|
})
|
|
|
|
plugin.Serve(&plugin.ServeConfig{
|
|
HandshakeConfig: base.Handshake,
|
|
Plugins: map[string]plugin.Plugin{
|
|
docklog.PluginName: docklog.NewPlugin(docklog.NewDockerLogger(logger)),
|
|
},
|
|
GRPCServer: plugin.DefaultGRPCServer,
|
|
Logger: logger,
|
|
})
|
|
|
|
return
|
|
}
|
|
}
|
|
|
|
// Serve the plugin
|
|
plugins.ServeCtx(factory)
|
|
}
|
|
|
|
// factory returns a new instance of the docker driver plugin
|
|
func factory(ctx context.Context, log log.Logger) interface{} {
|
|
return docker.NewDockerDriver(ctx, log)
|
|
}
|