Skip to content

Commit

Permalink
Make nodenames unique in Gossip cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Santhosh Manohar <[email protected]>
  • Loading branch information
Santhosh Manohar committed Sep 16, 2016
1 parent c8ce8c7 commit 3ab83e3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sort"

"github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/go-events"
"github.com/docker/libnetwork/datastore"
"github.com/docker/libnetwork/discoverapi"
Expand Down Expand Up @@ -246,10 +247,25 @@ func (c *controller) agentInit(bindAddrOrInterface, advertiseAddr string) error
}

keys, tags := c.getKeys(subsysGossip)

// Make the hostname unique in the gossip cluster by appending a 12
// byte random ID. Between distros there is no consensus if the
// hostname should be an FQDN or shortname. Limit the hostname to
// RFC 1123 compliant 63 bytes
hostname, _ := os.Hostname()
id := stringid.TruncateID(stringid.GenerateRandomID())

var nodeName string
if len(hostname)+len(id) > 63 {
nodeName = hostname[:63-len(id)] + "-" + id
} else {
nodeName = hostname + "-" + id
}
logrus.Infof("Gossip cluster hostname ", nodeName)

nDB, err := networkdb.New(&networkdb.Config{
AdvertiseAddr: advertiseAddr,
NodeName: hostname,
NodeName: nodeName,
Keys: keys,
})

Expand Down

0 comments on commit 3ab83e3

Please sign in to comment.