Skip to content

Commit

Permalink
Merge pull request #1053 from hashicorp/remove-interfaces
Browse files Browse the repository at this point in the history
removing interfaces from config
  • Loading branch information
diptanu committed Apr 9, 2016
2 parents 4b232b5 + bed0f2b commit d8d24c0
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 120 deletions.
30 changes: 2 additions & 28 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

// Set up the ports
Expand Down Expand Up @@ -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 {
Expand Down
37 changes: 0 additions & 37 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -378,7 +366,6 @@ func DefaultConfig() *Config {
Serf: 4648,
},
Addresses: &Addresses{},
Interfaces: &Interfaces{},
AdvertiseAddrs: &AdvertiseAddrs{},
Atlas: &AtlasConfig{},
Client: &ClientConfig{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 0 additions & 39 deletions command/agent/config_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 0 additions & 16 deletions website/source/docs/agent/config.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,6 @@ nodes, unless otherwise specified:
server nodes from the same datacenter if possible. Used only on server
nodes.

* <a id="interfaces">`interfaces`</a>: Provides an alternative to the
`addresses` configuration. Operators can provide network device names to which
Nomad binds individual network services. Nomad looks for the first IPv4
address configured for the device and uses it, and if no IPv4 address is
present then it looks for an IPv6 address. The value is a map of device names of
network interfaces and supports the following keys:
<br>
* `http`: The device name the HTTP server is bound to. Applies to both clients and servers.
* `rpc`: The device name to bind the internal RPC interfaces to. Should be exposed
only to other cluster members if possible. Used only on server nodes, but
must be accessible from all agents.
* `serf`: The device name used to bind the gossip layer to. Both a TCP and UDP
listener will be exposed on this address. Should be restricted to only
server nodes from the same datacenter if possible. Used only on server
nodes.

* `advertise`: Controls the advertise address for individual network services.
This can be used to advertise a different address to the peers of a server
node to support more complex network configurations such as NAT. This
Expand Down

0 comments on commit d8d24c0

Please sign in to comment.