2018-11-29 13:59:53 +00:00
|
|
|
package executor
|
2016-02-09 20:59:05 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2018-09-24 18:37:45 +00:00
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
2019-01-05 00:08:47 +00:00
|
|
|
plugin "github.com/hashicorp/go-plugin"
|
2016-02-09 20:59:05 +00:00
|
|
|
)
|
|
|
|
|
2018-11-29 13:59:53 +00:00
|
|
|
// ExecutorConfig is the config that Nomad passes to the executor
|
|
|
|
type ExecutorConfig struct {
|
|
|
|
|
|
|
|
// LogFile is the file to which Executor logs
|
|
|
|
LogFile string
|
|
|
|
|
|
|
|
// LogLevel is the level of the logs to putout
|
|
|
|
LogLevel string
|
|
|
|
|
|
|
|
// FSIsolation if set will use an executor implementation that support
|
|
|
|
// filesystem isolation
|
|
|
|
FSIsolation bool
|
|
|
|
}
|
|
|
|
|
2019-01-09 23:06:58 +00:00
|
|
|
func GetPluginMap(logger hclog.Logger, fsIsolation bool) map[string]plugin.Plugin {
|
2016-02-10 02:24:30 +00:00
|
|
|
return map[string]plugin.Plugin{
|
2019-01-09 23:06:58 +00:00
|
|
|
"executor": &ExecutorPlugin{
|
|
|
|
logger: logger,
|
|
|
|
fsIsolation: fsIsolation,
|
|
|
|
},
|
2016-02-10 02:24:30 +00:00
|
|
|
}
|
2016-02-09 20:59:05 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 17:25:59 +00:00
|
|
|
func GetPre09PluginMap(logger hclog.Logger, fsIsolation bool) map[string]plugin.Plugin {
|
|
|
|
return map[string]plugin.Plugin{
|
|
|
|
"executor": newPre09ExecutorPlugin(logger),
|
2019-01-13 21:05:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-11 18:53:39 +00:00
|
|
|
// ExecutorReattachConfig is the config that we serialize and de-serialize and
|
2016-02-09 20:59:05 +00:00
|
|
|
// store in disk
|
|
|
|
type PluginReattachConfig struct {
|
|
|
|
Pid int
|
|
|
|
AddrNet string
|
|
|
|
AddrName string
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginConfig returns a config from an ExecutorReattachConfig
|
|
|
|
func (c *PluginReattachConfig) PluginConfig() *plugin.ReattachConfig {
|
|
|
|
var addr net.Addr
|
|
|
|
switch c.AddrNet {
|
|
|
|
case "unix", "unixgram", "unixpacket":
|
|
|
|
addr, _ = net.ResolveUnixAddr(c.AddrNet, c.AddrName)
|
|
|
|
case "tcp", "tcp4", "tcp6":
|
|
|
|
addr, _ = net.ResolveTCPAddr(c.AddrNet, c.AddrName)
|
|
|
|
}
|
|
|
|
return &plugin.ReattachConfig{Pid: c.Pid, Addr: addr}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPluginReattachConfig(c *plugin.ReattachConfig) *PluginReattachConfig {
|
|
|
|
return &PluginReattachConfig{Pid: c.Pid, AddrNet: c.Addr.Network(), AddrName: c.Addr.String()}
|
|
|
|
}
|