github.com/hernad/nomad@v1.6.112/drivers/nix/_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  // ExecutorReattachConfig is the config that we serialize and de-serialize and
    34  // store in disk
    35  type PluginReattachConfig struct {
    36  	Pid      int
    37  	AddrNet  string
    38  	AddrName string
    39  }
    40  
    41  // PluginConfig returns a config from an ExecutorReattachConfig
    42  func (c *PluginReattachConfig) PluginConfig() *plugin.ReattachConfig {
    43  	var addr net.Addr
    44  	switch c.AddrNet {
    45  	case "unix", "unixgram", "unixpacket":
    46  		addr, _ = net.ResolveUnixAddr(c.AddrNet, c.AddrName)
    47  	case "tcp", "tcp4", "tcp6":
    48  		addr, _ = net.ResolveTCPAddr(c.AddrNet, c.AddrName)
    49  	}
    50  	return &plugin.ReattachConfig{Pid: c.Pid, Addr: addr}
    51  }
    52  
    53  func NewPluginReattachConfig(c *plugin.ReattachConfig) *PluginReattachConfig {
    54  	return &PluginReattachConfig{Pid: c.Pid, AddrNet: c.Addr.Network(), AddrName: c.Addr.String()}
    55  }