github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/drivers/shared/executor/plugins.go (about)

     1  package executor
     2  
     3  import (
     4  	"net"
     5  
     6  	hclog "github.com/hashicorp/go-hclog"
     7  	plugin "github.com/hashicorp/go-plugin"
     8  )
     9  
    10  // ExecutorConfig is the config that Nomad passes to the executor
    11  type ExecutorConfig struct {
    12  
    13  	// LogFile is the file to which Executor logs
    14  	LogFile string
    15  
    16  	// LogLevel is the level of the logs to putout
    17  	LogLevel string
    18  
    19  	// FSIsolation if set will use an executor implementation that support
    20  	// filesystem isolation
    21  	FSIsolation bool
    22  }
    23  
    24  func GetPluginMap(logger hclog.Logger, fsIsolation bool) map[string]plugin.Plugin {
    25  	return map[string]plugin.Plugin{
    26  		"executor": &ExecutorPlugin{
    27  			logger:      logger,
    28  			fsIsolation: fsIsolation,
    29  		},
    30  	}
    31  }
    32  
    33  func GetPre09PluginMap(logger hclog.Logger, fsIsolation bool) map[string]plugin.Plugin {
    34  	return map[string]plugin.Plugin{
    35  		"executor": newPre09ExecutorPlugin(logger),
    36  	}
    37  }
    38  
    39  // ExecutorReattachConfig is the config that we serialize and de-serialize and
    40  // store in disk
    41  type PluginReattachConfig struct {
    42  	Pid      int
    43  	AddrNet  string
    44  	AddrName string
    45  }
    46  
    47  // PluginConfig returns a config from an ExecutorReattachConfig
    48  func (c *PluginReattachConfig) PluginConfig() *plugin.ReattachConfig {
    49  	var addr net.Addr
    50  	switch c.AddrNet {
    51  	case "unix", "unixgram", "unixpacket":
    52  		addr, _ = net.ResolveUnixAddr(c.AddrNet, c.AddrName)
    53  	case "tcp", "tcp4", "tcp6":
    54  		addr, _ = net.ResolveTCPAddr(c.AddrNet, c.AddrName)
    55  	}
    56  	return &plugin.ReattachConfig{Pid: c.Pid, Addr: addr}
    57  }
    58  
    59  func NewPluginReattachConfig(c *plugin.ReattachConfig) *PluginReattachConfig {
    60  	return &PluginReattachConfig{Pid: c.Pid, AddrNet: c.Addr.Network(), AddrName: c.Addr.String()}
    61  }