diff --git a/command/agent/agent.go b/command/agent/agent.go index 58099a202..dd1f81518 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -65,7 +65,10 @@ func (a *Agent) setupServer() error { } // Setup the configuration - conf := nomad.DefaultConfig() + conf := a.config.NomadConfig + if conf == nil { + conf = nomad.DefaultConfig() + } conf.LogOutput = a.logOutput conf.DevMode = a.config.DevMode conf.Build = fmt.Sprintf("%s%s", a.config.Version, a.config.VersionPrerelease) @@ -130,7 +133,10 @@ func (a *Agent) setupClient() error { } // Setup the configuration - conf := client.DefaultConfig() + conf := a.config.ClientConfig + if conf == nil { + conf = client.DefaultConfig() + } if a.server != nil { conf.RPCHandler = a.server } diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 37f373893..32a0e24b6 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -1,10 +1,15 @@ package agent import ( + "fmt" "io/ioutil" + "net" "os" "sync/atomic" "testing" + "time" + + "github.com/hashicorp/nomad/nomad" ) var nextPort uint32 = 17000 @@ -25,6 +30,32 @@ func makeAgent(t *testing.T, cb func(*Config)) (string, *Agent) { dir := tmpDir(t) conf := DevConfig() + // Customize the server configuration + config := nomad.DefaultConfig() + conf.NomadConfig = config + + // Only use loopback + config.RPCAddr = &net.TCPAddr{ + IP: []byte{127, 0, 0, 1}, + Port: getPort(), + } + config.NodeName = fmt.Sprintf("Node %d", config.RPCAddr.Port) + + // Tighten the Serf timing + config.SerfConfig.MemberlistConfig.BindAddr = "127.0.0.1" + config.SerfConfig.MemberlistConfig.BindPort = getPort() + config.SerfConfig.MemberlistConfig.SuspicionMult = 2 + config.SerfConfig.MemberlistConfig.RetransmitMult = 2 + config.SerfConfig.MemberlistConfig.ProbeTimeout = 50 * time.Millisecond + config.SerfConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond + config.SerfConfig.MemberlistConfig.GossipInterval = 100 * time.Millisecond + + // Tighten the Raft timing + config.RaftConfig.LeaderLeaseTimeout = 20 * time.Millisecond + config.RaftConfig.HeartbeatTimeout = 40 * time.Millisecond + config.RaftConfig.ElectionTimeout = 40 * time.Millisecond + config.RaftTimeout = 500 * time.Millisecond + if cb != nil { cb(conf) } diff --git a/command/agent/config.go b/command/agent/config.go index fe25d59c2..84b78f208 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -10,6 +10,8 @@ import ( "github.com/hashicorp/hcl" hclobj "github.com/hashicorp/hcl/hcl" + client "github.com/hashicorp/nomad/client/config" + "github.com/hashicorp/nomad/nomad" ) // Config is the configuration for the Nomad agent. @@ -57,6 +59,14 @@ type Config struct { VersionPrerelease string DevMode bool `hcl:"-"` + + // NomadConfig is used to override the default config. + // This is largly used for testing purposes. + NomadConfig *nomad.Config `hcl:"-" json:"-"` + + // ClientConfig is used to override the default config. + // This is largly used for testing purposes. + ClientConfig *client.Config `hcl:"-" json:"-"` } type ClientConfig struct {