|
|
|
@ -4,7 +4,6 @@ import ( |
|
|
|
|
"context" |
|
|
|
|
"fmt" |
|
|
|
|
sysruntime "runtime" |
|
|
|
|
"slices" |
|
|
|
|
|
|
|
|
|
"github.com/Masterminds/semver/v3" |
|
|
|
|
"github.com/grafana/grafana-app-sdk/logging" |
|
|
|
@ -12,10 +11,8 @@ import ( |
|
|
|
|
"github.com/grafana/grafana/apps/advisor/pkg/app/checks" |
|
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services" |
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/repo" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/managedplugins" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginchecker" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/provisionedplugins" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
@ -66,10 +63,8 @@ func (c *check) Item(ctx context.Context, id string) (any, error) { |
|
|
|
|
func (c *check) Steps() []checks.Step { |
|
|
|
|
return []checks.Step{ |
|
|
|
|
&deprecationStep{ |
|
|
|
|
PluginRepo: c.PluginRepo, |
|
|
|
|
PluginPreinstall: c.PluginPreinstall, |
|
|
|
|
ManagedPlugins: c.ManagedPlugins, |
|
|
|
|
ProvisionedPlugins: c.ProvisionedPlugins, |
|
|
|
|
PluginRepo: c.PluginRepo, |
|
|
|
|
updateChecker: c.updateChecker, |
|
|
|
|
}, |
|
|
|
|
&updateStep{ |
|
|
|
|
PluginRepo: c.PluginRepo, |
|
|
|
@ -79,11 +74,8 @@ func (c *check) Steps() []checks.Step { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type deprecationStep struct { |
|
|
|
|
PluginRepo repo.Service |
|
|
|
|
PluginPreinstall plugininstaller.Preinstall |
|
|
|
|
ManagedPlugins managedplugins.Manager |
|
|
|
|
ProvisionedPlugins provisionedplugins.Manager |
|
|
|
|
provisionedPlugins []string |
|
|
|
|
PluginRepo repo.Service |
|
|
|
|
updateChecker pluginchecker.PluginUpdateChecker |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *deprecationStep) Title() string { |
|
|
|
@ -109,21 +101,7 @@ func (s *deprecationStep) Run(ctx context.Context, log logging.Logger, _ *adviso |
|
|
|
|
return nil, fmt.Errorf("invalid item type %T", it) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Skip if it's a core plugin
|
|
|
|
|
if p.IsCorePlugin() { |
|
|
|
|
log.Debug("Skipping core plugin", "plugin", p.ID) |
|
|
|
|
return nil, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Skip if it's managed or pinned
|
|
|
|
|
if s.isManaged(ctx, p.ID) || s.PluginPreinstall.IsPinned(p.ID) { |
|
|
|
|
log.Debug("Skipping managed or pinned plugin", "plugin", p.ID) |
|
|
|
|
return nil, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Skip if it's provisioned
|
|
|
|
|
if s.isProvisioned(ctx, p.ID) { |
|
|
|
|
log.Debug("Skipping provisioned plugin", "plugin", p.ID) |
|
|
|
|
if !s.updateChecker.IsUpdatable(ctx, p) { |
|
|
|
|
return nil, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -216,24 +194,3 @@ func hasUpdate(current pluginstore.Plugin, latest *repo.PluginArchiveInfo) bool |
|
|
|
|
// In other case, assume that a different latest version will always be newer
|
|
|
|
|
return current.Info.Version != latest.Version |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Temporary duplicated code until there is a common IsUpdatable function
|
|
|
|
|
func (s *deprecationStep) isManaged(ctx context.Context, pluginID string) bool { |
|
|
|
|
for _, managedPlugin := range s.ManagedPlugins.ManagedPlugins(ctx) { |
|
|
|
|
if managedPlugin == pluginID { |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *deprecationStep) isProvisioned(ctx context.Context, pluginID string) bool { |
|
|
|
|
if s.provisionedPlugins == nil { |
|
|
|
|
var err error |
|
|
|
|
s.provisionedPlugins, err = s.ProvisionedPlugins.ProvisionedPlugins(ctx) |
|
|
|
|
if err != nil { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return slices.Contains(s.provisionedPlugins, pluginID) |
|
|
|
|
} |
|
|
|
|