removing interfaces from config
This commit is contained in:
parent
f6b56540b3
commit
891b201eef
|
@ -127,29 +127,10 @@ func (a *Agent) serverConfig() (*nomad.Config, error) {
|
|||
}
|
||||
if addr := a.config.Addresses.RPC; addr != "" {
|
||||
conf.RPCAddr.IP = net.ParseIP(addr)
|
||||
} else if device := a.config.Interfaces.RPC; device != "" {
|
||||
ip, err := ipOfDevice(device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conf.RPCAddr.IP = ip
|
||||
}
|
||||
if addr := a.config.Addresses.Serf; addr != "" {
|
||||
conf.SerfConfig.MemberlistConfig.BindAddr = addr
|
||||
} else if device := a.config.Interfaces.Serf; device != "" {
|
||||
ip, err := ipOfDevice(device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conf.SerfConfig.MemberlistConfig.BindAddr = ip.String()
|
||||
}
|
||||
|
||||
if device := a.config.Interfaces.HTTP; device != "" && a.config.Addresses.HTTP == "" {
|
||||
ip, err := ipOfDevice(device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a.config.Addresses.HTTP = ip.String()
|
||||
if addr := a.config.Addresses.Serf; addr != "" {
|
||||
conf.SerfConfig.MemberlistConfig.BindAddr = addr
|
||||
}
|
||||
|
||||
// Set up the ports
|
||||
|
@ -232,18 +213,11 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) {
|
|||
|
||||
// Setting the proper HTTP Addr
|
||||
httpAddr := fmt.Sprintf("%s:%d", a.config.BindAddr, a.config.Ports.HTTP)
|
||||
if a.config.Addresses.HTTP != "" && a.config.AdvertiseAddrs.HTTP == "" && a.config.Interfaces.HTTP == "" {
|
||||
if a.config.Addresses.HTTP != "" && a.config.AdvertiseAddrs.HTTP == "" {
|
||||
httpAddr = fmt.Sprintf("%s:%d", a.config.Addresses.HTTP, a.config.Ports.HTTP)
|
||||
if _, err := net.ResolveTCPAddr("tcp", httpAddr); err != nil {
|
||||
return nil, fmt.Errorf("error resolving http addr: %v:", err)
|
||||
}
|
||||
} else if a.config.Interfaces.HTTP != "" && a.config.AdvertiseAddrs.HTTP == "" {
|
||||
ip, err := ipOfDevice(a.config.Interfaces.HTTP)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error finding ip address from interface %q: %v", a.config.Interfaces.HTTP, err)
|
||||
}
|
||||
a.config.Addresses.HTTP = ip.String()
|
||||
httpAddr = fmt.Sprintf("%s:%d", ip.String(), a.config.Ports.HTTP)
|
||||
} else if a.config.AdvertiseAddrs.HTTP != "" {
|
||||
addr, err := net.ResolveTCPAddr("tcp", a.config.AdvertiseAddrs.HTTP)
|
||||
if err != nil {
|
||||
|
|
|
@ -46,10 +46,6 @@ type Config struct {
|
|||
// Addresses is used to override the network addresses we bind to.
|
||||
Addresses *Addresses `mapstructure:"addresses"`
|
||||
|
||||
// Interfaces is used to override the network addresses we bind to by
|
||||
// providing device names
|
||||
Interfaces *Interfaces `mapstructure:"interfaces"`
|
||||
|
||||
// AdvertiseAddrs is used to control the addresses we advertise.
|
||||
AdvertiseAddrs *AdvertiseAddrs `mapstructure:"advertise"`
|
||||
|
||||
|
@ -259,14 +255,6 @@ type Addresses struct {
|
|||
Serf string `mapstructure:"serf"`
|
||||
}
|
||||
|
||||
// Interfaces provides an alternative to the Addresses configuration. We pick an
|
||||
// ip configured on the devide specified and use that to bind.
|
||||
type Interfaces struct {
|
||||
HTTP string `mapstructure:"http"`
|
||||
RPC string `mapstructure:"rpc"`
|
||||
Serf string `mapstructure:"serf"`
|
||||
}
|
||||
|
||||
// AdvertiseAddrs is used to control the addresses we advertise out for
|
||||
// different network services. Not all network services support an
|
||||
// advertise address. All are optional and default to BindAddr.
|
||||
|
@ -378,7 +366,6 @@ func DefaultConfig() *Config {
|
|||
Serf: 4648,
|
||||
},
|
||||
Addresses: &Addresses{},
|
||||
Interfaces: &Interfaces{},
|
||||
AdvertiseAddrs: &AdvertiseAddrs{},
|
||||
Atlas: &AtlasConfig{},
|
||||
Client: &ClientConfig{
|
||||
|
@ -509,14 +496,6 @@ func (c *Config) Merge(b *Config) *Config {
|
|||
result.Addresses = result.Addresses.Merge(b.Addresses)
|
||||
}
|
||||
|
||||
// Apply the interfaces config
|
||||
if result.Interfaces == nil && b.Interfaces != nil {
|
||||
interfaces := *b.Interfaces
|
||||
result.Interfaces = &interfaces
|
||||
} else if b.Interfaces != nil {
|
||||
result.Interfaces = result.Interfaces.Merge(b.Interfaces)
|
||||
}
|
||||
|
||||
// Apply the advertise addrs config
|
||||
if result.AdvertiseAddrs == nil && b.AdvertiseAddrs != nil {
|
||||
advertise := *b.AdvertiseAddrs
|
||||
|
@ -696,22 +675,6 @@ func (a *Addresses) Merge(b *Addresses) *Addresses {
|
|||
return &result
|
||||
}
|
||||
|
||||
// Merge is used to merge two interfaces configs together.
|
||||
func (i *Interfaces) Merge(b *Interfaces) *Interfaces {
|
||||
result := *i
|
||||
|
||||
if b.HTTP != "" {
|
||||
result.HTTP = b.HTTP
|
||||
}
|
||||
if b.RPC != "" {
|
||||
result.RPC = b.RPC
|
||||
}
|
||||
if b.Serf != "" {
|
||||
result.Serf = b.Serf
|
||||
}
|
||||
return &result
|
||||
}
|
||||
|
||||
// Merge merges two advertise addrs configs together.
|
||||
func (a *AdvertiseAddrs) Merge(b *AdvertiseAddrs) *AdvertiseAddrs {
|
||||
result := *a
|
||||
|
|
|
@ -130,13 +130,6 @@ func parseConfig(result *Config, list *ast.ObjectList) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Parse interfaces
|
||||
if o := list.Filter("interfaces"); len(o.Items) > 0 {
|
||||
if err := parseInterfaces(&result.Interfaces, o); err != nil {
|
||||
return multierror.Prefix(err, "interfaces ->")
|
||||
}
|
||||
}
|
||||
|
||||
// Parse advertise
|
||||
if o := list.Filter("advertise"); len(o.Items) > 0 {
|
||||
if err := parseAdvertise(&result.AdvertiseAddrs, o); err != nil {
|
||||
|
@ -253,38 +246,6 @@ func parseAddresses(result **Addresses, list *ast.ObjectList) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func parseInterfaces(result **Interfaces, list *ast.ObjectList) error {
|
||||
list = list.Elem()
|
||||
if len(list.Items) > 1 {
|
||||
return fmt.Errorf("only one 'interfaces' block allowed")
|
||||
}
|
||||
|
||||
// Get our interfaces object
|
||||
listVal := list.Items[0].Val
|
||||
|
||||
// Check for the invalid keys
|
||||
valid := []string{
|
||||
"http",
|
||||
"rpc",
|
||||
"serf",
|
||||
}
|
||||
if err := checkHCLKeys(listVal, valid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var m map[string]interface{}
|
||||
if err := hcl.DecodeObject(&m, listVal); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var interfaces Interfaces
|
||||
if err := mapstructure.WeakDecode(m, &interfaces); err != nil {
|
||||
return err
|
||||
}
|
||||
*result = &interfaces
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseAdvertise(result **AdvertiseAddrs, list *ast.ObjectList) error {
|
||||
list = list.Elem()
|
||||
if len(list.Items) > 1 {
|
||||
|
|
Loading…
Reference in a new issue