Distill config.Config.ConsulConfig down to config.Config.Consul
The enclosed struct provides the necessary context
This commit is contained in:
parent
bfa4711df5
commit
840b49a720
|
@ -489,14 +489,14 @@ func (a *Agent) Stats() map[string]map[string]string {
|
|||
|
||||
func (a *Agent) createAgentConfig() {
|
||||
cfg := &consul.AgentConfig{
|
||||
Addr: a.config.ConsulConfig.Addr,
|
||||
Token: a.config.ConsulConfig.Token,
|
||||
Auth: a.config.ConsulConfig.Auth,
|
||||
EnableSSL: a.config.ConsulConfig.EnableSSL,
|
||||
VerifySSL: a.config.ConsulConfig.VerifySSL,
|
||||
CAFile: a.config.ConsulConfig.CAFile,
|
||||
CertFile: a.config.ConsulConfig.CertFile,
|
||||
KeyFile: a.config.ConsulConfig.KeyFile,
|
||||
Addr: a.config.Consul.Addr,
|
||||
Token: a.config.Consul.Token,
|
||||
Auth: a.config.Consul.Auth,
|
||||
EnableSSL: a.config.Consul.EnableSSL,
|
||||
VerifySSL: a.config.Consul.VerifySSL,
|
||||
CAFile: a.config.Consul.CAFile,
|
||||
CertFile: a.config.Consul.CertFile,
|
||||
KeyFile: a.config.Consul.KeyFile,
|
||||
}
|
||||
a.consulAgentConfig = cfg
|
||||
}
|
||||
|
@ -509,20 +509,20 @@ func (a *Agent) syncAgentServicesWithConsul(clientHttpAddr string, serverHttpAdd
|
|||
}
|
||||
a.consulService = cs
|
||||
var services []*structs.Service
|
||||
if a.client != nil && a.config.ConsulConfig.ClientServiceName != "" {
|
||||
if a.client != nil && a.config.Consul.ClientServiceName != "" {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
clientService := &structs.Service{
|
||||
Name: a.config.ConsulConfig.ClientServiceName,
|
||||
Name: a.config.Consul.ClientServiceName,
|
||||
PortLabel: clientHttpAddr,
|
||||
}
|
||||
services = append(services, clientService)
|
||||
cs.SetServiceIdentifier("agent-client")
|
||||
}
|
||||
if a.server != nil && a.config.ConsulConfig.ServerServiceName != "" {
|
||||
if a.server != nil && a.config.Consul.ServerServiceName != "" {
|
||||
serverService := &structs.Service{
|
||||
Name: a.config.ConsulConfig.ServerServiceName,
|
||||
Name: a.config.Consul.ServerServiceName,
|
||||
PortLabel: serverHttpAddr,
|
||||
}
|
||||
services = append(services, serverService)
|
||||
|
|
|
@ -42,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.ConsulConfig = &ConsulConfig{}
|
||||
conf.Consul = &ConsulConfig{}
|
||||
|
||||
// Tighten the Serf timing
|
||||
config.SerfConfig.MemberlistConfig.SuspicionMult = 2
|
||||
|
|
|
@ -60,7 +60,7 @@ func (c *Command) readConfig() *Config {
|
|||
// Make a new, empty config.
|
||||
cmdConfig := &Config{
|
||||
Atlas: &AtlasConfig{},
|
||||
ConsulConfig: &ConsulConfig{},
|
||||
Consul: &Consul{},
|
||||
Client: &ClientConfig{},
|
||||
Ports: &Ports{},
|
||||
Server: &ServerConfig{},
|
||||
|
|
|
@ -82,9 +82,10 @@ type Config struct {
|
|||
// AtlasConfig is used to configure Atlas
|
||||
Atlas *AtlasConfig `mapstructure:"atlas"`
|
||||
|
||||
// ConsulConfig is used to configure Consul clients and register the nomad
|
||||
// server and client services with Consul
|
||||
ConsulConfig *ConsulConfig `mapstructure:"consul"`
|
||||
// Consul contains the configuration for the Consul Agent and
|
||||
// parameters necessary to register services, their checks, and
|
||||
// discover the current Nomad servers.
|
||||
Consul *ConsulConfig `mapstructure:"consul"`
|
||||
|
||||
// NomadConfig is used to override the default config.
|
||||
// This is largly used for testing purposes.
|
||||
|
@ -128,8 +129,13 @@ type AtlasConfig struct {
|
|||
Endpoint string `mapstructure:"endpoint"`
|
||||
}
|
||||
|
||||
// ConsulConfig is used to configure Consul clients and register the nomad
|
||||
// server and client services with Consul
|
||||
// ConsulConfig contains the configuration information necessary to
|
||||
// communicate with a Consul Agent in order to:
|
||||
//
|
||||
// - Register services and checks with Consul
|
||||
//
|
||||
// - Bootstrap this Nomad Client with the list of Nomad Servers registered
|
||||
// with Consul
|
||||
type ConsulConfig struct {
|
||||
|
||||
// ServerServiceName is the name of the service that Nomad uses to register
|
||||
|
@ -439,7 +445,7 @@ func DefaultConfig() *Config {
|
|||
Addresses: &Addresses{},
|
||||
AdvertiseAddrs: &AdvertiseAddrs{},
|
||||
Atlas: &AtlasConfig{},
|
||||
ConsulConfig: &ConsulConfig{
|
||||
Consul: &ConsulConfig{
|
||||
ServerServiceName: "nomad-server",
|
||||
ClientServiceName: "nomad-client",
|
||||
},
|
||||
|
@ -593,11 +599,11 @@ func (c *Config) Merge(b *Config) *Config {
|
|||
}
|
||||
|
||||
// Apply the Consul Configuration
|
||||
if result.ConsulConfig == nil && b.ConsulConfig != nil {
|
||||
consulConfig := *b.ConsulConfig
|
||||
result.ConsulConfig = &consulConfig
|
||||
} else if b.ConsulConfig != nil {
|
||||
result.ConsulConfig = result.ConsulConfig.Merge(b.ConsulConfig)
|
||||
if result.Consul == nil && b.Consul != nil {
|
||||
consulConfig := *b.Consul
|
||||
result.Consul = &consulConfig
|
||||
} else if b.Consul != nil {
|
||||
result.Consul = result.Consul.Merge(b.Consul)
|
||||
}
|
||||
|
||||
// Merge config files lists
|
||||
|
|
|
@ -169,7 +169,7 @@ func parseConfig(result *Config, list *ast.ObjectList) error {
|
|||
|
||||
// Parse the consul config
|
||||
if o := list.Filter("consul"); len(o.Items) > 0 {
|
||||
if err := parseConsulConfig(&result.ConsulConfig, o); err != nil {
|
||||
if err := parseConsulConfig(&result.Consul, o); err != nil {
|
||||
return multierror.Prefix(err, "consul ->")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ func TestConfig_Parse(t *testing.T) {
|
|||
Join: true,
|
||||
Endpoint: "127.0.0.1:1234",
|
||||
},
|
||||
ConsulConfig: &ConsulConfig{
|
||||
Consul: &ConsulConfig{
|
||||
ServerServiceName: "nomad-server",
|
||||
ClientServiceName: "nomad-client",
|
||||
Addr: "127.0.0.1:9500",
|
||||
|
|
Loading…
Reference in a new issue