Using map to list plugins in node description

Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
(cherry picked from commit feedb7ab5a)
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Nishant Totla 2016-07-25 17:16:31 -07:00 committed by Tibor Vass
parent 678a19ef6b
commit 25cf7999fa

View file

@ -32,13 +32,13 @@ func (e *executor) Describe(ctx context.Context) (*api.NodeDescription, error) {
return nil, err
}
var plugins []api.PluginDescription
plugins := map[api.PluginDescription]struct{}{}
addPlugins := func(typ string, names []string) {
for _, name := range names {
plugins = append(plugins, api.PluginDescription{
plugins[api.PluginDescription{
Type: typ,
Name: name,
})
}] = struct{}{}
}
}
@ -48,7 +48,12 @@ func (e *executor) Describe(ctx context.Context) (*api.NodeDescription, error) {
addPlugins("Network", append([]string{"overlay"}, info.Plugins.Network...))
addPlugins("Authorization", info.Plugins.Authorization)
sort.Sort(sortedPlugins(plugins))
pluginFields := make([]api.PluginDescription, 0, len(plugins))
for k := range plugins {
pluginFields = append(pluginFields, k)
}
sort.Sort(sortedPlugins(pluginFields))
// parse []string labels into a map[string]string
labels := map[string]string{}
@ -70,7 +75,7 @@ func (e *executor) Describe(ctx context.Context) (*api.NodeDescription, error) {
Engine: &api.EngineDescription{
EngineVersion: info.ServerVersion,
Labels: labels,
Plugins: plugins,
Plugins: pluginFields,
},
Resources: &api.Resources{
NanoCPUs: int64(info.NCPU) * 1e9,