Create config.DefaultConsulConfig()
This commit is contained in:
parent
8f01a2e638
commit
d17af396ca
|
@ -131,12 +131,7 @@ func (c *Config) Copy() *Config {
|
|||
// DefaultConfig returns the default configuration
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
ConsulConfig: &config.ConsulConfig{
|
||||
ServerServiceName: "nomad",
|
||||
ClientServiceName: "nomad-client",
|
||||
AutoAdvertise: true,
|
||||
Timeout: 5 * time.Second,
|
||||
},
|
||||
ConsulConfig: config.DefaultConsulConfig(),
|
||||
LogOutput: os.Stderr,
|
||||
Region: "global",
|
||||
StatsCollectionInterval: 1 * time.Second,
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/nomad"
|
||||
cconfig "github.com/hashicorp/nomad/nomad/structs/config"
|
||||
)
|
||||
|
||||
var nextPort uint32 = 17000
|
||||
|
@ -43,7 +42,7 @@ func makeAgent(t testing.TB, cb func(*Config)) (string, *Agent) {
|
|||
Serf: getPort(),
|
||||
}
|
||||
conf.NodeName = fmt.Sprintf("Node %d", conf.Ports.RPC)
|
||||
conf.Consul = &cconfig.ConsulConfig{}
|
||||
conf.Consul = &config.DefaultConsulConfig()
|
||||
|
||||
// Tighten the Serf timing
|
||||
config.SerfConfig.MemberlistConfig.SuspicionMult = 2
|
||||
|
|
|
@ -61,7 +61,7 @@ func (c *Command) readConfig() *Config {
|
|||
// Make a new, empty config.
|
||||
cmdConfig := &Config{
|
||||
Atlas: &AtlasConfig{},
|
||||
Consul: &config.ConsulConfig{},
|
||||
Consul: config.DefaultConsulConfig(),
|
||||
Client: &ClientConfig{},
|
||||
Ports: &Ports{},
|
||||
Server: &ServerConfig{},
|
||||
|
|
|
@ -377,14 +377,7 @@ func DefaultConfig() *Config {
|
|||
Addresses: &Addresses{},
|
||||
AdvertiseAddrs: &AdvertiseAddrs{},
|
||||
Atlas: &AtlasConfig{},
|
||||
Consul: &config.ConsulConfig{
|
||||
ServerServiceName: "nomad",
|
||||
ClientServiceName: "nomad-client",
|
||||
AutoAdvertise: true,
|
||||
ServerAutoJoin: true,
|
||||
ClientAutoJoin: true,
|
||||
Timeout: 5 * time.Second,
|
||||
},
|
||||
Consul: config.DefaultConsulConfig(),
|
||||
Client: &ClientConfig{
|
||||
Enabled: false,
|
||||
NetworkSpeed: 100,
|
||||
|
|
|
@ -557,7 +557,7 @@ func parseConsulConfig(result **config.ConsulConfig, list *ast.ObjectList) error
|
|||
return fmt.Errorf("only one 'consul' block allowed")
|
||||
}
|
||||
|
||||
// Get our consul object
|
||||
// Get our Consul object
|
||||
listVal := list.Items[0].Val
|
||||
|
||||
// Check for invalid keys
|
||||
|
@ -587,7 +587,7 @@ func parseConsulConfig(result **config.ConsulConfig, list *ast.ObjectList) error
|
|||
return err
|
||||
}
|
||||
|
||||
var consulConfig config.ConsulConfig
|
||||
consulConfig := config.DefaultConsulConfig()
|
||||
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
||||
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
|
||||
WeaklyTypedInput: true,
|
||||
|
@ -600,7 +600,7 @@ func parseConsulConfig(result **config.ConsulConfig, list *ast.ObjectList) error
|
|||
return err
|
||||
}
|
||||
|
||||
*result = &consulConfig
|
||||
*result = consulConfig
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ import (
|
|||
"github.com/hashicorp/consul/lib"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
|
||||
cconfig "github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs/config"
|
||||
"github.com/hashicorp/nomad/nomad/types"
|
||||
|
@ -160,7 +159,7 @@ func NewSyncer(consulConfig *config.ConsulConfig, shutdownCh chan struct{}, logg
|
|||
|
||||
// If a nil consulConfig was provided, fall back to the default config
|
||||
if consulConfig == nil {
|
||||
consulConfig = cconfig.DefaultConfig().ConsulConfig
|
||||
consulConfig = config.DefaultConsulConfig()
|
||||
}
|
||||
|
||||
if consulConfig.Addr != "" {
|
||||
|
|
|
@ -46,7 +46,7 @@ func TestConsulServiceRegisterServices(t *testing.T) {
|
|||
t.Skip()
|
||||
|
||||
shutdownCh := make(chan struct{})
|
||||
cs, err := NewSyncer(&config.ConsulConfig{}, shutdownCh, logger)
|
||||
cs, err := NewSyncer(&config.DefaultConsulConfig(), shutdownCh, logger)
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func TestConsulServiceUpdateService(t *testing.T) {
|
|||
t.Skip()
|
||||
|
||||
shutdownCh := make(chan struct{})
|
||||
cs, err := NewSyncer(&config.ConsulConfig{}, shutdownCh, logger)
|
||||
cs, err := NewSyncer(&config.DefaultConsulConfig(), shutdownCh, logger)
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
|
|
|
@ -225,6 +225,7 @@ func DefaultConfig() *Config {
|
|||
MaxHeartbeatsPerSecond: 50.0,
|
||||
HeartbeatGrace: 10 * time.Second,
|
||||
FailoverHeartbeatTTL: 300 * time.Second,
|
||||
ConsulConfig: config.DefaultConsulConfig(),
|
||||
}
|
||||
|
||||
// Enable all known schedulers by default
|
||||
|
|
|
@ -67,6 +67,19 @@ type ConsulConfig struct {
|
|||
ClientAutoJoin bool `mapstructure:"client_auto_join"`
|
||||
}
|
||||
|
||||
// DefaultConsulConfig() returns the canonical defaults for the Nomad
|
||||
// `consul` configuration.
|
||||
func DefaultConsulConfig() *ConsulConfig {
|
||||
return &ConsulConfig{
|
||||
ServerServiceName: "nomad",
|
||||
ClientServiceName: "nomad-client",
|
||||
AutoAdvertise: true,
|
||||
ServerAutoJoin: true,
|
||||
ClientAutoJoin: true,
|
||||
Timeout: 5 * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
// Merge merges two Consul Configurations together.
|
||||
func (a *ConsulConfig) Merge(b *ConsulConfig) *ConsulConfig {
|
||||
result := *a
|
||||
|
|
Loading…
Reference in New Issue