mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
da65825c5f
commit
fa49fe3331
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/plugins/manager/loader/assetpath"
|
"github.com/grafana/grafana/pkg/plugins/manager/loader/assetpath"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pluginFactoryFunc func(p plugins.FoundPlugin, pluginClass plugins.Class, sig plugins.Signature) (*plugins.Plugin, error)
|
type pluginFactoryFunc func(p *plugins.FoundBundle, pluginClass plugins.Class, sig plugins.Signature) (*plugins.Plugin, error)
|
||||||
|
|
||||||
// DefaultPluginFactory is the default plugin factory used by the Construct step of the Bootstrap stage.
|
// DefaultPluginFactory is the default plugin factory used by the Construct step of the Bootstrap stage.
|
||||||
//
|
//
|
||||||
@ -23,8 +23,31 @@ func NewDefaultPluginFactory(assetPath *assetpath.Service) *DefaultPluginFactory
|
|||||||
return &DefaultPluginFactory{assetPath: assetPath}
|
return &DefaultPluginFactory{assetPath: assetPath}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *DefaultPluginFactory) createPlugin(p plugins.FoundPlugin, class plugins.Class,
|
func (f *DefaultPluginFactory) createPlugin(bundle *plugins.FoundBundle, class plugins.Class,
|
||||||
sig plugins.Signature) (*plugins.Plugin, error) {
|
sig plugins.Signature) (*plugins.Plugin, error) {
|
||||||
|
plugin, err := f.newPlugin(bundle.Primary, class, sig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bundle.Children) == 0 {
|
||||||
|
return plugin, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.Children = make([]*plugins.Plugin, 0, len(bundle.Children))
|
||||||
|
for _, child := range bundle.Children {
|
||||||
|
cp, err := f.newPlugin(*child, class, sig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cp.Parent = plugin
|
||||||
|
plugin.Children = append(plugin.Children, cp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugin, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *DefaultPluginFactory) newPlugin(p plugins.FoundPlugin, class plugins.Class, sig plugins.Signature) (*plugins.Plugin, error) {
|
||||||
info := assetpath.NewPluginInfo(p.JSONData, class, p.FS)
|
info := assetpath.NewPluginInfo(p.JSONData, class, p.FS)
|
||||||
baseURL, err := f.assetPath.Base(info)
|
baseURL, err := f.assetPath.Base(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -49,7 +72,6 @@ func (f *DefaultPluginFactory) createPlugin(p plugins.FoundPlugin, class plugins
|
|||||||
if err = setImages(plugin, f.assetPath); err != nil {
|
if err = setImages(plugin, f.assetPath); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin, nil
|
return plugin, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
// 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) {
|
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)
|
sig, err := c.signatureCalculator.Calculate(ctx, src, bundle.Primary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.log.Warn("Could not calculate plugin signature state", "pluginId", bundle.Primary.JSONData.ID, "error", err)
|
c.log.Warn("Could not calculate plugin signature state", "pluginId", bundle.Primary.JSONData.ID, "error", err)
|
||||||
return nil, 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 {
|
if err != nil {
|
||||||
c.log.Error("Could not create primary plugin base", "pluginId", bundle.Primary.JSONData.ID, "error", err)
|
c.log.Error("Could not create primary plugin base", "pluginId", bundle.Primary.JSONData.ID, "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
res := make([]*plugins.Plugin, 0, len(plugin.Children)+1)
|
||||||
res = append(res, plugin)
|
res = append(res, plugin)
|
||||||
|
res = append(res, plugin.Children...)
|
||||||
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...)
|
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user