Plugins: Make it possible to support multiple plugin versions (#82116)
* first pass * use version in more places * add comment * update installer * fix wire * fix tests * tidy * simplify changes * fix in mem * remove unused step * fix step dupe logic for child plugins + add tests
This commit is contained in:
@@ -6,9 +6,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/loader/finder"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
||||
)
|
||||
|
||||
// DefaultFindFunc is the default function used for the Find step of the Discovery stage. It will scan the local
|
||||
@@ -17,44 +15,6 @@ func DefaultFindFunc(cfg *config.Cfg) FindFunc {
|
||||
return finder.NewLocalFinder(cfg.DevMode, cfg.Features).Find
|
||||
}
|
||||
|
||||
// DuplicatePluginValidation is a filter step that will filter out any plugins that are already registered with the
|
||||
// registry. This includes both the primary plugin and any child plugins, which are matched using the plugin ID field.
|
||||
type DuplicatePluginValidation struct {
|
||||
registry registry.Service
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
// NewDuplicatePluginFilterStep returns a new DuplicatePluginValidation.
|
||||
func NewDuplicatePluginFilterStep(registry registry.Service) *DuplicatePluginValidation {
|
||||
return &DuplicatePluginValidation{
|
||||
registry: registry,
|
||||
log: log.New("plugins.dedupe"),
|
||||
}
|
||||
}
|
||||
|
||||
// Filter will filter out any plugins that are already registered with the registry.
|
||||
func (d *DuplicatePluginValidation) Filter(ctx context.Context, bundles []*plugins.FoundBundle) ([]*plugins.FoundBundle, error) {
|
||||
res := make([]*plugins.FoundBundle, 0, len(bundles))
|
||||
for _, b := range bundles {
|
||||
_, exists := d.registry.Plugin(ctx, b.Primary.JSONData.ID)
|
||||
if exists {
|
||||
d.log.Warn("Skipping loading of plugin as it's a duplicate", "pluginId", b.Primary.JSONData.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, child := range b.Children {
|
||||
_, exists = d.registry.Plugin(ctx, child.JSONData.ID)
|
||||
if exists {
|
||||
d.log.Warn("Skipping loading of child plugin as it's a duplicate", "pluginId", child.JSONData.ID)
|
||||
continue
|
||||
}
|
||||
}
|
||||
res = append(res, b)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// PermittedPluginTypesFilter is a filter step that will filter out any plugins that are not of a permitted type.
|
||||
type PermittedPluginTypesFilter struct {
|
||||
permittedTypes []plugins.Type
|
||||
|
||||
@@ -54,7 +54,7 @@ func newDeregister(pluginRegistry registry.Service) *Deregister {
|
||||
|
||||
// Deregister removes a plugin from the plugin registry.
|
||||
func (d *Deregister) Deregister(ctx context.Context, p *plugins.Plugin) error {
|
||||
if err := d.pluginRegistry.Remove(ctx, p.ID); err != nil {
|
||||
if err := d.pluginRegistry.Remove(ctx, p.ID, p.Info.Version); err != nil {
|
||||
return err
|
||||
}
|
||||
d.log.Debug("Plugin unregistered", "pluginId", p.ID)
|
||||
|
||||
Reference in New Issue
Block a user