rename NomadConfig to ClientAgentConfig

This commit is contained in:
Nick Ethier
2018-10-29 21:34:34 -04:00
parent b837bf3ce3
commit 95d381cff7
25 changed files with 67 additions and 68 deletions

View File

@@ -368,9 +368,9 @@ func (c *Config) ReadStringListToMapDefault(key, defaultValue string) map[string
}
// NomadPluginConfig produces the NomadConfig struct which is sent to Nomad plugins
func (c *Config) NomadPluginConfig() *base.NomadConfig {
return &base.NomadConfig{
Driver: &base.NomadDriverConfig{
func (c *Config) NomadPluginConfig() *base.ClientAgentConfig {
return &base.ClientAgentConfig{
Driver: &base.ClientDriverConfig{
ClientMinPort: c.ClientMinPort,
ClientMaxPort: c.ClientMaxPort,
},

View File

@@ -230,10 +230,7 @@ func TestUniversalExecutor_MakeExecutable(t *testing.T) {
// Set its permissions to be non-executable
f.Chmod(os.FileMode(0610))
// Make a fake executor
executor := NewExecutor(testlog.HCLogger(t)).(*UniversalExecutor)
err = executor.makeExecutable(f.Name())
err = makeExecutable(f.Name())
if err != nil {
t.Fatalf("makeExecutable() failed: %v", err)
}

View File

@@ -585,11 +585,11 @@ func TestFingerprintManager_Run_DriverFailure(t *testing.T) {
dispenseCalls := 0
loader := &loader.MockCatalog{
DispenseF: func(name, pluginType string, logger log.Logger) (loader.PluginInstance, error) {
DispenseF: func(name, pluginType string, cfg *base.ClientAgentConfig, logger log.Logger) (loader.PluginInstance, error) {
if pluginType == base.PluginTypeDriver && name == "raw_exec" {
dispenseCalls++
}
return singLoader.Dispense(name, pluginType, logger)
return singLoader.Dispense(name, pluginType, cfg, logger)
},
ReattachF: singLoader.Reattach,
CatalogF: singLoader.Catalog,

View File

@@ -121,7 +121,7 @@ func (d *NvidiaDevice) ConfigSchema() (*hclspec.Spec, error) {
}
// SetConfig is used to set the configuration of the plugin.
func (d *NvidiaDevice) SetConfig(data []byte, cfg *base.NomadConfig) error {
func (d *NvidiaDevice) SetConfig(data []byte, cfg *base.ClientAgentConfig) error {
var config Config
if err := base.MsgPackDecode(data, &config); err != nil {
return err

View File

@@ -73,7 +73,7 @@ type ExecDriver struct {
config *Config
// nomadConfig is the client config from nomad
nomadConfig *base.NomadDriverConfig
nomadConfig *base.ClientDriverConfig
// tasks is the in memory datastore mapping taskIDs to execDriverHandles
tasks *taskStore
@@ -135,7 +135,7 @@ func (*ExecDriver) ConfigSchema() (*hclspec.Spec, error) {
return configSpec, nil
}
func (d *ExecDriver) SetConfig(data []byte, cfg *base.NomadConfig) error {
func (d *ExecDriver) SetConfig(data []byte, cfg *base.ClientAgentConfig) error {
var config Config
if err := base.MsgPackDecode(data, &config); err != nil {
return err

View File

@@ -212,7 +212,7 @@ func (d *Driver) ConfigSchema() (*hclspec.Spec, error) {
return configSpec, nil
}
func (d *Driver) SetConfig(data []byte, cfg *base.NomadConfig) error {
func (d *Driver) SetConfig(data []byte, cfg *base.ClientAgentConfig) error {
var config Config
if err := base.MsgPackDecode(data, &config); err != nil {
return err

View File

@@ -106,7 +106,7 @@ type RawExecDriver struct {
config *Config
// nomadConfig is the client config from nomad
nomadConfig *base.NomadDriverConfig
nomadConfig *base.ClientDriverConfig
// tasks is the in memory datastore mapping taskIDs to rawExecDriverHandles
tasks *taskStore
@@ -172,7 +172,7 @@ func (r *RawExecDriver) ConfigSchema() (*hclspec.Spec, error) {
return configSpec, nil
}
func (r *RawExecDriver) SetConfig(data []byte, cfg *base.NomadConfig) error {
func (r *RawExecDriver) SetConfig(data []byte, cfg *base.ClientAgentConfig) error {
var config Config
if err := base.MsgPackDecode(data, &config); err != nil {
return err

View File

@@ -43,20 +43,20 @@ func TestRawExecDriver_SetConfig(t *testing.T) {
var data []byte
require.NoError(basePlug.MsgPackEncode(&data, config))
require.NoError(harness.SetConfig(data))
require.NoError(harness.SetConfig(data, nil))
require.Exactly(config, d.(*RawExecDriver).config)
config.Enabled = true
config.NoCgroups = true
data = []byte{}
require.NoError(basePlug.MsgPackEncode(&data, config))
require.NoError(harness.SetConfig(data))
require.NoError(harness.SetConfig(data, nil))
require.Exactly(config, d.(*RawExecDriver).config)
config.NoCgroups = false
data = []byte{}
require.NoError(basePlug.MsgPackEncode(&data, config))
require.NoError(harness.SetConfig(data))
require.NoError(harness.SetConfig(data, nil))
require.Exactly(config, d.(*RawExecDriver).config)
}
@@ -72,7 +72,7 @@ func TestRawExecDriver_Fingerprint(t *testing.T) {
var data []byte
require.NoError(basePlug.MsgPackEncode(&data, config))
require.NoError(harness.SetConfig(data))
require.NoError(harness.SetConfig(data, nil))
fingerCh, err := harness.Fingerprint(context.Background())
require.NoError(err)
@@ -88,7 +88,7 @@ func TestRawExecDriver_Fingerprint(t *testing.T) {
config.Enabled = true
data = []byte{}
require.NoError(basePlug.MsgPackEncode(&data, config))
require.NoError(harness.SetConfig(data))
require.NoError(harness.SetConfig(data, nil))
FINGER_LOOP:
for {

View File

@@ -154,7 +154,7 @@ type RktDriver struct {
config *Config
// nomadConfig is the client config from nomad
nomadConfig *base.NomadDriverConfig
nomadConfig *base.ClientDriverConfig
// tasks is the in memory datastore mapping taskIDs to rktTaskHandles
tasks *taskStore
@@ -193,7 +193,7 @@ func (d *RktDriver) ConfigSchema() (*hclspec.Spec, error) {
return configSpec, nil
}
func (d *RktDriver) SetConfig(data []byte, cfg *base.NomadConfig) error {
func (d *RktDriver) SetConfig(data []byte, cfg *base.ClientAgentConfig) error {
var config Config
if err := base.MsgPackDecode(data, &config); err != nil {
return err

View File

@@ -64,13 +64,13 @@ func TestRktDriver_SetConfig(t *testing.T) {
var data []byte
require.NoError(basePlug.MsgPackEncode(&data, config))
require.NoError(harness.SetConfig(data))
require.NoError(harness.SetConfig(data, nil))
require.Exactly(config, d.(*RktDriver).config)
config.VolumesEnabled = false
data = []byte{}
require.NoError(basePlug.MsgPackEncode(&data, config))
require.NoError(harness.SetConfig(data))
require.NoError(harness.SetConfig(data, nil))
require.Exactly(config, d.(*RktDriver).config)
}
@@ -434,7 +434,7 @@ func TestRktDriver_Start_Wait_Volume(t *testing.T) {
var data []byte
require.NoError(basePlug.MsgPackEncode(&data, config))
require.NoError(harness.SetConfig(data))
require.NoError(harness.SetConfig(data, nil))
task := &drivers.TaskConfig{
ID: uuid.Generate(),

View File

@@ -15,7 +15,7 @@ type BasePlugin interface {
// SetConfig is used to set the configuration by passing a MessagePack
// encoding of it.
SetConfig(data []byte, config *NomadConfig) error
SetConfig(data []byte, config *ClientAgentConfig) error
}
// PluginInfoResponse returns basic information about the plugin such that Nomad
@@ -35,13 +35,13 @@ type PluginInfoResponse struct {
Name string
}
// NomadConfig is the nomad client configuration sent to all plugins
type NomadConfig struct {
Driver *NomadDriverConfig
// ClientAgentConfig is the nomad client configuration sent to all plugins
type ClientAgentConfig struct {
Driver *ClientDriverConfig
}
// NomadDriverConfig is the driver specific configuration for all driver plugins
type NomadDriverConfig struct {
// ClientDriverConfig is the driver specific configuration for all driver plugins
type ClientDriverConfig struct {
// ClientMaxPort is the upper range of the ports that the client uses for
// communicating with plugin subsystems over loopback
ClientMaxPort uint
@@ -51,7 +51,7 @@ type NomadDriverConfig struct {
ClientMinPort uint
}
func (c *NomadConfig) toProto() *proto.NomadConfig {
func (c *ClientAgentConfig) toProto() *proto.NomadConfig {
if c == nil {
return nil
}
@@ -68,14 +68,14 @@ func (c *NomadConfig) toProto() *proto.NomadConfig {
return cfg
}
func nomadConfigFromProto(pb *proto.NomadConfig) *NomadConfig {
func nomadConfigFromProto(pb *proto.NomadConfig) *ClientAgentConfig {
if pb == nil {
return nil
}
cfg := &NomadConfig{}
cfg := &ClientAgentConfig{}
if pb.Driver != nil {
cfg.Driver = &NomadDriverConfig{
cfg.Driver = &ClientDriverConfig{
ClientMaxPort: uint(pb.Driver.ClientMaxPort),
ClientMinPort: uint(pb.Driver.ClientMinPort),
}

View File

@@ -49,7 +49,7 @@ func (b *BasePluginClient) ConfigSchema() (*hclspec.Spec, error) {
return presp.GetSpec(), nil
}
func (b *BasePluginClient) SetConfig(data []byte, config *NomadConfig) error {
func (b *BasePluginClient) SetConfig(data []byte, config *ClientAgentConfig) error {
// Send the config
_, err := b.Client.SetConfig(context.Background(), &proto.SetConfigRequest{
MsgpackConfig: data,

View File

@@ -118,7 +118,7 @@ func TestBasePlugin_SetConfig(t *testing.T) {
ConfigSchemaF: func() (*hclspec.Spec, error) {
return TestSpec, nil
},
SetConfigF: func(data []byte, cfg *NomadConfig) error {
SetConfigF: func(data []byte, cfg *ClientAgentConfig) error {
receivedData = data
return nil
},
@@ -147,7 +147,7 @@ func TestBasePlugin_SetConfig(t *testing.T) {
})
cdata, err := msgpack.Marshal(config, config.Type())
require.NoError(err)
require.NoError(impl.SetConfig(cdata, &NomadConfig{}))
require.NoError(impl.SetConfig(cdata, &ClientAgentConfig{}))
require.Equal(cdata, receivedData)
// Decode the value back

View File

@@ -62,7 +62,7 @@ func (b *basePluginServer) SetConfig(ctx context.Context, req *proto.SetConfigRe
// Client configuration is filtered based on plugin type
cfg := nomadConfigFromProto(req.GetNomadConfig())
filteredCfg := new(NomadConfig)
filteredCfg := new(ClientAgentConfig)
switch info.Type {
case PluginTypeDriver:

View File

@@ -52,9 +52,11 @@ type TestConfig struct {
type MockPlugin struct {
PluginInfoF func() (*PluginInfoResponse, error)
ConfigSchemaF func() (*hclspec.Spec, error)
SetConfigF func([]byte, *NomadConfig) error
SetConfigF func([]byte, *ClientAgentConfig) error
}
func (p *MockPlugin) PluginInfo() (*PluginInfoResponse, error) { return p.PluginInfoF() }
func (p *MockPlugin) ConfigSchema() (*hclspec.Spec, error) { return p.ConfigSchemaF() }
func (p *MockPlugin) SetConfig(data []byte, cfg *NomadConfig) error { return p.SetConfigF(data, cfg) }
func (p *MockPlugin) PluginInfo() (*PluginInfoResponse, error) { return p.PluginInfoF() }
func (p *MockPlugin) ConfigSchema() (*hclspec.Spec, error) { return p.ConfigSchemaF() }
func (p *MockPlugin) SetConfig(data []byte, cfg *ClientAgentConfig) error {
return p.SetConfigF(data, cfg)
}

View File

@@ -116,7 +116,7 @@ func (d *FsDevice) ConfigSchema() (*hclspec.Spec, error) {
}
// SetConfig is used to set the configuration of the plugin.
func (d *FsDevice) SetConfig(data []byte, cfg *base.NomadConfig) error {
func (d *FsDevice) SetConfig(data []byte, cfg *base.ClientAgentConfig) error {
var config Config
if err := base.MsgPackDecode(data, &config); err != nil {
return err

View File

@@ -131,7 +131,7 @@ func TestDevicePlugin_SetConfig(t *testing.T) {
ConfigSchemaF: func() (*hclspec.Spec, error) {
return base.TestSpec, nil
},
SetConfigF: func(data []byte) error {
SetConfigF: func(data []byte, cfg *base.ClientAgentConfig) error {
receivedData = data
return nil
},
@@ -162,7 +162,7 @@ func TestDevicePlugin_SetConfig(t *testing.T) {
})
cdata, err := msgpack.Marshal(config, config.Type())
require.NoError(err)
require.NoError(impl.SetConfig(cdata))
require.NoError(impl.SetConfig(cdata, nil))
require.Equal(cdata, receivedData)
// Decode the value back

View File

@@ -26,7 +26,7 @@ func CgroupsMounted(node *structs.Node) bool {
// CreateExecutor launches an executor plugin and returns an instance of the
// Executor interface
func CreateExecutor(w io.Writer, level hclog.Level, nomadConfig *base.NomadDriverConfig,
func CreateExecutor(w io.Writer, level hclog.Level, nomadConfig *base.ClientDriverConfig,
executorConfig *dstructs.ExecutorConfig) (executor.Executor, *plugin.Client, error) {
c, err := json.Marshal(executorConfig)

View File

@@ -52,7 +52,7 @@ General Options:
` + generalOptionsUsage() + `
Device Options:
-trace
Enable trace level log output.
`
@@ -119,7 +119,7 @@ func (c *Device) Run(args []string) int {
}
c.spec = spec
if err := c.setConfig(spec, config); err != nil {
if err := c.setConfig(spec, config, nil); err != nil {
c.logger.Error("failed to set config", "error", err)
return 1
}
@@ -187,7 +187,7 @@ func (c *Device) getSpec() (hcldec.Spec, error) {
return schema, nil
}
func (c *Device) setConfig(spec hcldec.Spec, config []byte) error {
func (c *Device) setConfig(spec hcldec.Spec, config []byte, nmdCfg *base.ClientAgentConfig) error {
// Parse the config into hcl
configVal, err := hclConfigToInterface(config)
if err != nil {
@@ -216,7 +216,7 @@ func (c *Device) setConfig(spec hcldec.Spec, config []byte) error {
}
c.logger.Trace("msgpack config", "config", string(cdata))
if err := c.dev.SetConfig(cdata); err != nil {
if err := c.dev.SetConfig(cdata, nmdCfg); err != nil {
return err
}

View File

@@ -18,7 +18,7 @@ import (
type PluginCatalog interface {
// Dispense returns the plugin given its name and type. This will also
// configure the plugin
Dispense(name, pluginType string, config *base.NomadConfig, logger log.Logger) (PluginInstance, error)
Dispense(name, pluginType string, config *base.ClientAgentConfig, logger log.Logger) (PluginInstance, error)
// Reattach is used to reattach to a previously launched external plugin.
Reattach(name, pluginType string, config *plugin.ReattachConfig) (PluginInstance, error)
@@ -114,7 +114,7 @@ func NewPluginLoader(config *PluginLoaderConfig) (*PluginLoader, error) {
// Dispense returns a plugin instance, loading it either internally or by
// launching an external plugin.
func (l *PluginLoader) Dispense(name, pluginType string, config *base.NomadConfig, logger log.Logger) (PluginInstance, error) {
func (l *PluginLoader) Dispense(name, pluginType string, config *base.ClientAgentConfig, logger log.Logger) (PluginInstance, error) {
id := PluginID{
Name: name,
PluginType: pluginType,

View File

@@ -698,8 +698,8 @@ func TestPluginLoader_Dispense_Internal(t *testing.T) {
defer h.cleanup()
expKey := "set_config_worked"
expNomadConfig := &base.NomadConfig{
Driver: &base.NomadDriverConfig{
expNomadConfig := &base.ClientAgentConfig{
Driver: &base.ClientDriverConfig{
ClientMinPort: 100,
},
}

View File

@@ -100,7 +100,7 @@ type mockPlugin struct {
// config is built on SetConfig
config *mockPluginConfig
// nomadconfig is set on SetConfig
nomadConfig *base.NomadConfig
nomadConfig *base.ClientAgentConfig
}
// mockPluginConfig is the configuration for the mock plugin
@@ -140,7 +140,7 @@ func (m *mockPlugin) ConfigSchema() (*hclspec.Spec, error) {
}
// SetConfig decodes the configuration and stores it
func (m *mockPlugin) SetConfig(data []byte, cfg *base.NomadConfig) error {
func (m *mockPlugin) SetConfig(data []byte, cfg *base.ClientAgentConfig) error {
var config mockPluginConfig
if err := base.MsgPackDecode(data, &config); err != nil {
return err

View File

@@ -8,12 +8,12 @@ import (
// MockCatalog provides a mock PluginCatalog to be used for testing
type MockCatalog struct {
DispenseF func(name, pluginType string, cfg *base.NomadConfig, logger log.Logger) (PluginInstance, error)
DispenseF func(name, pluginType string, cfg *base.ClientAgentConfig, logger log.Logger) (PluginInstance, error)
ReattachF func(name, pluginType string, config *plugin.ReattachConfig) (PluginInstance, error)
CatalogF func() map[string][]*base.PluginInfoResponse
}
func (m *MockCatalog) Dispense(name, pluginType string, cfg *base.NomadConfig, logger log.Logger) (PluginInstance, error) {
func (m *MockCatalog) Dispense(name, pluginType string, cfg *base.ClientAgentConfig, logger log.Logger) (PluginInstance, error) {
return m.DispenseF(name, pluginType, cfg, logger)
}

View File

@@ -43,7 +43,7 @@ func (s *SingletonLoader) Catalog() map[string][]*base.PluginInfoResponse {
// Dispense returns the plugin given its name and type. This will also
// configure the plugin. If there is an instance of an already running plugin,
// this is used.
func (s *SingletonLoader) Dispense(name, pluginType string, config *base.NomadConfig, logger log.Logger) (loader.PluginInstance, error) {
func (s *SingletonLoader) Dispense(name, pluginType string, config *base.ClientAgentConfig, logger log.Logger) (loader.PluginInstance, error) {
return s.getPlugin(false, name, pluginType, logger, config, nil)
}
@@ -55,7 +55,7 @@ func (s *SingletonLoader) Reattach(name, pluginType string, config *plugin.Reatt
// getPlugin is a helper that either dispenses or reattaches to a plugin using
// futures to ensure only a single instance is retrieved
func (s *SingletonLoader) getPlugin(reattach bool, name, pluginType string, logger log.Logger,
nomadConfig *base.NomadConfig, config *plugin.ReattachConfig) (loader.PluginInstance, error) {
nomadConfig *base.ClientAgentConfig, config *plugin.ReattachConfig) (loader.PluginInstance, error) {
// Lock the instance map to prevent races
s.instanceLock.Lock()
@@ -95,7 +95,7 @@ func (s *SingletonLoader) getPlugin(reattach bool, name, pluginType string, logg
// dispense should be called in a go routine to not block and creates the
// desired plugin, setting the results in the future.
func (s *SingletonLoader) dispense(f *future, name, pluginType string, config *base.NomadConfig, logger log.Logger) {
func (s *SingletonLoader) dispense(f *future, name, pluginType string, config *base.ClientAgentConfig, logger log.Logger) {
i, err := s.loader.Dispense(name, pluginType, config, logger)
f.set(i, err)
}

View File

@@ -27,7 +27,7 @@ func TestSingleton_Dispense(t *testing.T) {
dispenseCalled := 0
s, c := harness(t)
c.DispenseF = func(_, _ string, _ *base.NomadConfig, _ log.Logger) (loader.PluginInstance, error) {
c.DispenseF = func(_, _ string, _ *base.ClientAgentConfig, _ log.Logger) (loader.PluginInstance, error) {
p := &base.MockPlugin{}
i := &loader.MockInstance{
ExitedF: func() bool { return false },
@@ -77,7 +77,7 @@ func TestSingleton_Dispense_Exit_Dispense(t *testing.T) {
exited := false
dispenseCalled := 0
s, c := harness(t)
c.DispenseF = func(_, _ string, _ *base.NomadConfig, _ log.Logger) (loader.PluginInstance, error) {
c.DispenseF = func(_, _ string, _ *base.ClientAgentConfig, _ log.Logger) (loader.PluginInstance, error) {
p := &base.MockPlugin{}
i := &loader.MockInstance{
ExitedF: func() bool { return exited },
@@ -125,7 +125,7 @@ func TestSingleton_DispenseError_Dispense(t *testing.T) {
require := require.New(t)
dispenseCalled := 0
good := func(_, _ string, _ *base.NomadConfig, _ log.Logger) (loader.PluginInstance, error) {
good := func(_, _ string, _ *base.ClientAgentConfig, _ log.Logger) (loader.PluginInstance, error) {
p := &base.MockPlugin{}
i := &loader.MockInstance{
ExitedF: func() bool { return false },
@@ -135,7 +135,7 @@ func TestSingleton_DispenseError_Dispense(t *testing.T) {
return i, nil
}
bad := func(_, _ string, _ *base.NomadConfig, _ log.Logger) (loader.PluginInstance, error) {
bad := func(_, _ string, _ *base.ClientAgentConfig, _ log.Logger) (loader.PluginInstance, error) {
dispenseCalled++
return nil, fmt.Errorf("bad")
}
@@ -169,7 +169,7 @@ func TestSingleton_ReattachError_Dispense(t *testing.T) {
dispenseCalled, reattachCalled := 0, 0
s, c := harness(t)
c.DispenseF = func(_, _ string, _ *base.NomadConfig, _ log.Logger) (loader.PluginInstance, error) {
c.DispenseF = func(_, _ string, _ *base.ClientAgentConfig, _ log.Logger) (loader.PluginInstance, error) {
p := &base.MockPlugin{}
i := &loader.MockInstance{
ExitedF: func() bool { return false },
@@ -209,7 +209,7 @@ func TestSingleton_Reattach_Dispense(t *testing.T) {
dispenseCalled, reattachCalled := 0, 0
s, c := harness(t)
c.DispenseF = func(_, _ string, _ *base.NomadConfig, _ log.Logger) (loader.PluginInstance, error) {
c.DispenseF = func(_, _ string, _ *base.ClientAgentConfig, _ log.Logger) (loader.PluginInstance, error) {
dispenseCalled++
return nil, fmt.Errorf("bad")
}