From 7ca635a1ec2962358a5f7d3c021faca83ff5e55f Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Sat, 23 Jul 2016 19:57:53 +0200 Subject: [PATCH] daemon: no map[string]bool from GetNetworkDriverList No user of GetNetworkDriverList needs to access the map by key. The only user of GetNetworkDriverList is in docker info and with a map the network list is always flipping because loop is not deterministic. Fix this by returning a string slice which instead is. Signed-off-by: Antonio Murdaca --- daemon/info.go | 7 +------ daemon/network.go | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/daemon/info.go b/daemon/info.go index 0c1987918c..517d33c5d4 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -175,12 +175,7 @@ func (daemon *Daemon) showPluginsInfo() types.PluginsInfo { var pluginsInfo types.PluginsInfo pluginsInfo.Volume = volumedrivers.GetDriverList() - - networkDriverList := daemon.GetNetworkDriverList() - for nd := range networkDriverList { - pluginsInfo.Network = append(pluginsInfo.Network, nd) - } - + pluginsInfo.Network = daemon.GetNetworkDriverList() pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins return pluginsInfo diff --git a/daemon/network.go b/daemon/network.go index 57ec395e24..65c27fd1e1 100644 --- a/daemon/network.go +++ b/daemon/network.go @@ -3,6 +3,7 @@ package daemon import ( "fmt" "net" + "sort" "strings" "github.com/Sirupsen/logrus" @@ -328,21 +329,25 @@ func (daemon *Daemon) DisconnectContainerFromNetwork(containerName string, netwo // GetNetworkDriverList returns the list of plugins drivers // registered for network. -func (daemon *Daemon) GetNetworkDriverList() map[string]bool { - pluginList := make(map[string]bool) +func (daemon *Daemon) GetNetworkDriverList() []string { + pluginList := []string{} + pluginMap := make(map[string]bool) if !daemon.NetworkControllerEnabled() { return nil } - c := daemon.netController - networks := c.Networks() + networks := daemon.netController.Networks() for _, network := range networks { - driver := network.Type() - pluginList[driver] = true + if !pluginMap[network.Type()] { + pluginList = append(pluginList, network.Type()) + pluginMap[network.Type()] = true + } } // TODO : Replace this with proper libnetwork API - pluginList["overlay"] = true + pluginList = append(pluginList, "overlay") + + sort.Strings(pluginList) return pluginList }