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