Plugins: Use bundle instead of individual plugin during construct step (#91140)
* work off bundle instead of individual plugin * Remove children Co-authored-by: Giuseppe Guerra <giuseppe.guerra@grafana.com> * Remove children ref Co-authored-by: Giuseppe Guerra <giuseppe.guerra@grafana.com> * fix assign * end early * unset children --------- Co-authored-by: Giuseppe Guerra <giuseppe.guerra@grafana.com>
This commit is contained in:
co-authored by
Giuseppe Guerra
parent
da65825c5f
commit
fa49fe3331
@@ -47,34 +47,19 @@ func NewDefaultConstructor(signatureCalculator plugins.SignatureCalculator, asse
|
||||
|
||||
// Construct will calculate the plugin's signature state and create the plugin using the pluginFactoryFunc.
|
||||
func (c *DefaultConstructor) Construct(ctx context.Context, src plugins.PluginSource, bundle *plugins.FoundBundle) ([]*plugins.Plugin, error) {
|
||||
res := []*plugins.Plugin{}
|
||||
|
||||
sig, err := c.signatureCalculator.Calculate(ctx, src, bundle.Primary)
|
||||
if err != nil {
|
||||
c.log.Warn("Could not calculate plugin signature state", "pluginId", bundle.Primary.JSONData.ID, "error", err)
|
||||
return nil, err
|
||||
}
|
||||
plugin, err := c.pluginFactoryFunc(bundle.Primary, src.PluginClass(ctx), sig)
|
||||
plugin, err := c.pluginFactoryFunc(bundle, src.PluginClass(ctx), sig)
|
||||
if err != nil {
|
||||
c.log.Error("Could not create primary plugin base", "pluginId", bundle.Primary.JSONData.ID, "error", err)
|
||||
return nil, err
|
||||
}
|
||||
res := make([]*plugins.Plugin, 0, len(plugin.Children)+1)
|
||||
res = append(res, plugin)
|
||||
|
||||
children := make([]*plugins.Plugin, 0, len(bundle.Children))
|
||||
for _, child := range bundle.Children {
|
||||
cp, err := c.pluginFactoryFunc(*child, plugin.Class, sig)
|
||||
if err != nil {
|
||||
c.log.Error("Could not create child plugin base", "pluginId", child.JSONData.ID, "error", err)
|
||||
return nil, err
|
||||
}
|
||||
cp.Parent = plugin
|
||||
plugin.Children = append(plugin.Children, cp)
|
||||
|
||||
children = append(children, cp)
|
||||
}
|
||||
res = append(res, children...)
|
||||
|
||||
res = append(res, plugin.Children...)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user