Fix: Install plugins when they have no plugin archive info(catalog en… (#109200)

* fix: install plugins when they have URL is set

* test:INSTALL_PLUGINS private plugin with version
This commit is contained in:
Syerikjan Kh
2025-08-06 09:02:59 -04:00
committed by GitHub
parent 4e1333236c
commit abdb1c70ec
3 changed files with 24 additions and 2 deletions
@@ -101,7 +101,12 @@ func (s *Service) installPluginsWithTimeout(pluginsToInstall []setting.InstallPl
}
}
func (s *Service) shouldUpdate(ctx context.Context, pluginID, currentVersion string) bool {
func (s *Service) shouldUpdate(ctx context.Context, pluginID, currentVersion string, pluginURL string) bool {
// If the plugin is installed from a URL, we cannot check for updates as we do not have the version information
// from the repository. Therefore, we assume that the plugin should be updated if the URL is provided.
if pluginURL != "" {
return true
}
info, err := s.pluginRepo.GetPluginArchiveInfo(ctx, pluginID, "", repo.NewCompatOpts(s.cfg.BuildVersion, runtime.GOOS, runtime.GOARCH))
if err != nil {
s.log.Error("Failed to get plugin info", "pluginId", pluginID, "error", err)
@@ -128,7 +133,7 @@ func (s *Service) installPlugins(ctx context.Context, pluginsToInstall []setting
}
// The plugin is installed but it's not pinned to a specific version
// Check if there is a newer version available
if !s.shouldUpdate(ctx, installPlugin.ID, p.Info.Version) {
if !s.shouldUpdate(ctx, installPlugin.ID, p.Info.Version, installPlugin.URL) {
continue
}
}
@@ -144,6 +144,12 @@ func TestService_Run(t *testing.T) {
pluginsToInstallSync: []setting.InstallPlugin{{ID: "myplugin"}},
pluginsToInstall: []setting.InstallPlugin{{ID: "myplugin2"}},
},
{
name: "should install a plugin with a URL regardless of versioning",
shouldInstall: true,
pluginsToInstallSync: []setting.InstallPlugin{{ID: "our-plugin-datasource", URL: "https://s3.our.domain/grafana-plugins/our-plugin-datasource-1.2.1+linux.zip"}},
existingPlugins: []*plugins.Plugin{{JSONData: plugins.JSONData{ID: "our-plugin-datasource", Info: plugins.Info{Version: "1.2.2"}}}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {