From 3ab83e37dbc9ad84bd2560cc501e0a7746aeb02a Mon Sep 17 00:00:00 2001 From: Santhosh Manohar Date: Fri, 16 Sep 2016 15:15:46 -0700 Subject: [PATCH] Make nodenames unique in Gossip cluster Signed-off-by: Santhosh Manohar --- agent.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/agent.go b/agent.go index 2b2ecf4324..1ac4aa6e40 100644 --- a/agent.go +++ b/agent.go @@ -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" @@ -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, })