mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 06:02:49 +08:00
Plugin loader: refactor step evaluation (#85881)
This commit is contained in:

committed by
GitHub

parent
1e9841b1c9
commit
f375af793f
@ -10,7 +10,7 @@ import (
|
||||
|
||||
// Initializer is responsible for the Initialization stage of the plugin loader pipeline.
|
||||
type Initializer interface {
|
||||
Initialize(ctx context.Context, ps []*plugins.Plugin) ([]*plugins.Plugin, error)
|
||||
Initialize(ctx context.Context, ps *plugins.Plugin) (*plugins.Plugin, error)
|
||||
}
|
||||
|
||||
// InitializeFunc is the function used for the Initialize step of the Initialization stage.
|
||||
@ -40,28 +40,20 @@ func New(cfg *config.PluginManagementCfg, opts Opts) *Initialize {
|
||||
}
|
||||
|
||||
// Initialize will execute the Initialize steps of the Initialization stage.
|
||||
func (i *Initialize) Initialize(ctx context.Context, ps []*plugins.Plugin) ([]*plugins.Plugin, error) {
|
||||
func (i *Initialize) Initialize(ctx context.Context, ps *plugins.Plugin) (*plugins.Plugin, error) {
|
||||
if len(i.initializeSteps) == 0 {
|
||||
return ps, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
initializedPlugins := make([]*plugins.Plugin, 0, len(ps))
|
||||
for _, p := range ps {
|
||||
var ip *plugins.Plugin
|
||||
stepFailed := false
|
||||
for _, init := range i.initializeSteps {
|
||||
ip, err = init(ctx, p)
|
||||
if err != nil {
|
||||
stepFailed = true
|
||||
i.log.Error("Could not initialize plugin", "pluginId", p.ID, "error", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
if !stepFailed {
|
||||
initializedPlugins = append(initializedPlugins, ip)
|
||||
var ip *plugins.Plugin
|
||||
for _, init := range i.initializeSteps {
|
||||
ip, err = init(ctx, ps)
|
||||
if err != nil {
|
||||
i.log.Error("Could not initialize plugin", "pluginId", ps.ID, "error", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return initializedPlugins, nil
|
||||
return ip, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user