Merge pull request #713 from mavenugo/leave

log an error if advertise is configured with a non-local ip-address
This commit is contained in:
Jana Radhakrishnan 2015-10-26 13:48:55 -07:00
commit 6a2eee6632
2 changed files with 24 additions and 1 deletions

View file

@ -178,7 +178,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
if err := c.initDiscovery(cfg.Cluster.Watcher); err != nil {
// Failing to initalize discovery is a bad situation to be in.
// But it cannot fail creating the Controller
log.Debugf("Failed to Initialize Discovery : %v", err)
log.Errorf("Failed to Initialize Discovery : %v", err)
}
}

View file

@ -2,6 +2,7 @@ package overlay
import (
"fmt"
"net"
"sync"
"github.com/Sirupsen/logrus"
@ -120,8 +121,30 @@ func (d *driver) Type() string {
return networkType
}
func validateSelf(node string) error {
advIP := net.ParseIP(node)
if advIP == nil {
return fmt.Errorf("invalid self address (%s)", node)
}
addrs, err := net.InterfaceAddrs()
if err != nil {
return fmt.Errorf("Unable to get interface addresses %v", err)
}
for _, addr := range addrs {
ip, _, err := net.ParseCIDR(addr.String())
if err == nil && ip.Equal(advIP) {
return nil
}
}
return fmt.Errorf("Multi-Host overlay networking requires cluster-advertise(%s) to be configured with a local ip-address that is reachable within the cluster", advIP.String())
}
func (d *driver) nodeJoin(node string, self bool) {
if self && !d.isSerfAlive() {
if err := validateSelf(node); err != nil {
logrus.Errorf("%s", err.Error())
}
d.Lock()
d.bindAddress = node
d.Unlock()