Using map to list plugins in node description

Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
Nishant Totla 2016-07-25 17:16:31 -07:00
parent ebb157ec46
commit feedb7ab5a
No known key found for this signature in database
GPG key ID: 7EA5781C9B3D0C19

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,