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