mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
[core] Do not start the plugin loader on non-clients (#16111)
The plugin loader loads task and device driver plugins which are not used on server nodes.
This commit is contained in:
@@ -142,10 +142,6 @@ func NewAgent(config *Config, logger log.InterceptLogger, logOutput io.Writer, i
|
||||
return nil, fmt.Errorf("Failed to initialize Consul client: %v", err)
|
||||
}
|
||||
|
||||
if err := a.setupPlugins(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := a.setupServer(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -568,10 +564,6 @@ func (a *Agent) finalizeServerConfig(c *nomad.Config) {
|
||||
// Setup the logging
|
||||
c.Logger = a.logger
|
||||
c.LogOutput = a.logOutput
|
||||
|
||||
// Setup the plugin loaders
|
||||
c.PluginLoader = a.pluginLoader
|
||||
c.PluginSingletonLoader = a.pluginSingletonLoader
|
||||
c.AgentShutdown = func() error { return a.Shutdown() }
|
||||
}
|
||||
|
||||
@@ -1001,6 +993,14 @@ func (a *Agent) setupClient() error {
|
||||
if !a.config.Client.Enabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Plugin setup must happen before the call to clientConfig, because it
|
||||
// copies the pointers to the plugin loaders from the Agent to the
|
||||
// Client config.
|
||||
if err := a.setupPlugins(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Setup the configuration
|
||||
conf, err := a.clientConfig()
|
||||
if err != nil {
|
||||
|
||||
33
command/agent/plugins_test.go
Normal file
33
command/agent/plugins_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/shoenig/test/must"
|
||||
)
|
||||
|
||||
func TestPlugins_WhenNotClientSkip(t *testing.T) {
|
||||
s, _, _ := testServer(t, false, nil)
|
||||
must.Nil(t, s.Agent.pluginSingletonLoader)
|
||||
}
|
||||
|
||||
func TestPlugins_WhenClientRun(t *testing.T) {
|
||||
s, _, _ := testServer(t, true, nil)
|
||||
must.NotNil(t, s.Agent.pluginSingletonLoader)
|
||||
}
|
||||
|
||||
func testServer(t *testing.T, runClient bool, cb func(*Config)) (*TestAgent, *api.Client, string) {
|
||||
// Make a new test server
|
||||
a := NewTestAgent(t, t.Name(), func(config *Config) {
|
||||
config.Client.Enabled = runClient
|
||||
|
||||
if cb != nil {
|
||||
cb(config)
|
||||
}
|
||||
})
|
||||
t.Cleanup(a.Shutdown)
|
||||
|
||||
c := a.Client()
|
||||
return a, c, a.HTTPAddr()
|
||||
}
|
||||
Reference in New Issue
Block a user