Feature: Allow to load a core plugin as external (#75157)

This commit is contained in:
Andres Martinez Gotor
2023-09-22 10:50:13 +02:00
committed by GitHub
parent e0659c05da
commit 61cdfba87a
9 changed files with 139 additions and 0 deletions

View File

@ -157,3 +157,61 @@ func (c *DisablePlugins) Filter(bundles []*plugins.FoundBundle) ([]*plugins.Foun
}
return res, nil
}
// AsExternal is a filter step that will skip loading a core plugin to use an external one.
type AsExternal struct {
log log.Logger
cfg *config.Cfg
}
// NewDisablePluginsStep returns a new DisablePlugins.
func NewAsExternalStep(cfg *config.Cfg) *AsExternal {
return &AsExternal{
cfg: cfg,
log: log.New("plugins.asExternal"),
}
}
// Filter will filter out any plugins that are marked to be disabled.
func (c *AsExternal) Filter(cl plugins.Class, bundles []*plugins.FoundBundle) ([]*plugins.FoundBundle, error) {
if c.cfg.Features == nil || !c.cfg.Features.IsEnabled(featuremgmt.FlagExternalCorePlugins) {
return bundles, nil
}
if cl == plugins.ClassCore {
res := []*plugins.FoundBundle{}
for _, bundle := range bundles {
pluginCfg := c.cfg.PluginSettings[bundle.Primary.JSONData.ID]
// Skip core plugins if the feature flag is enabled and the plugin is in the skip list.
// It could be loaded later as an external plugin.
if pluginCfg["as_external"] == "true" {
c.log.Debug("Skipping the core plugin load", "pluginID", bundle.Primary.JSONData.ID)
} else {
res = append(res, bundle)
}
}
return res, nil
}
if cl == plugins.ClassExternal {
// Warn if the plugin is not found in the external plugins directory.
asExternal := map[string]bool{}
for pluginID, pluginCfg := range c.cfg.PluginSettings {
if pluginCfg["as_external"] == "true" {
asExternal[pluginID] = true
}
}
for _, bundle := range bundles {
if asExternal[bundle.Primary.JSONData.ID] {
delete(asExternal, bundle.Primary.JSONData.ID)
}
}
if len(asExternal) > 0 {
for p := range asExternal {
c.log.Error("Core plugin expected to be loaded as external, but it is missing", "pluginID", p)
}
}
}
return bundles, nil
}