K8s: Fix plugin updater (#101843)
This commit is contained in:
@@ -68,10 +68,11 @@ func ProvideBackgroundServiceRegistry(
|
||||
pluginInstaller *plugininstaller.Service,
|
||||
zanzanaReconciler *dualwrite.ZanzanaReconciler,
|
||||
appRegistry *appregistry.Service,
|
||||
pluginDashboardUpdater *plugindashboardsservice.DashboardUpdater,
|
||||
// Need to make sure these are initialized, is there a better place to put them?
|
||||
_ dashboardsnapshots.Service,
|
||||
_ serviceaccounts.Service, _ *guardian.Provider,
|
||||
_ *plugindashboardsservice.DashboardUpdater, _ *sanitizer.Provider,
|
||||
_ *sanitizer.Provider,
|
||||
_ *grpcserver.HealthService, _ *grpcserver.ReflectionService,
|
||||
_ *ldapapi.Service, _ *apiregistry.Service, _ auth.IDService, _ *teamapi.TeamAPI, _ ssosettings.Service,
|
||||
_ cloudmigration.Service, _ authnimpl.Registration,
|
||||
@@ -113,6 +114,7 @@ func ProvideBackgroundServiceRegistry(
|
||||
pluginInstaller,
|
||||
zanzanaReconciler,
|
||||
appRegistry,
|
||||
pluginDashboardUpdater,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
@@ -20,7 +21,6 @@ func ProvideDashboardUpdater(bus bus.Bus, pluginStore pluginstore.Store, pluginD
|
||||
dashboardPluginService dashboards.PluginService, dashboardService dashboards.DashboardService) *DashboardUpdater {
|
||||
du := newDashboardUpdater(bus, pluginStore, pluginDashboardService, dashboardImportService,
|
||||
pluginSettingsService, dashboardPluginService, dashboardService)
|
||||
du.updateAppDashboards()
|
||||
return du
|
||||
}
|
||||
|
||||
@@ -52,7 +52,12 @@ type DashboardUpdater struct {
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func (du *DashboardUpdater) updateAppDashboards() {
|
||||
func (du *DashboardUpdater) Run(ctx context.Context) error {
|
||||
du.updateAppDashboards(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (du *DashboardUpdater) updateAppDashboards(ctx context.Context) {
|
||||
du.logger.Debug("Looking for app dashboard updates")
|
||||
|
||||
pluginSettings, err := du.pluginSettingsService.GetPluginSettings(context.Background(), &pluginsettings.GetArgs{OrgID: 0})
|
||||
@@ -67,9 +72,10 @@ func (du *DashboardUpdater) updateAppDashboards() {
|
||||
continue
|
||||
}
|
||||
|
||||
if pluginDef, exists := du.pluginStore.Plugin(context.Background(), pluginSetting.PluginID); exists {
|
||||
serviceCtx, _ := identity.WithServiceIdentity(ctx, pluginSetting.OrgID)
|
||||
if pluginDef, exists := du.pluginStore.Plugin(serviceCtx, pluginSetting.PluginID); exists {
|
||||
if pluginDef.Info.Version != pluginSetting.PluginVersion {
|
||||
du.syncPluginDashboards(context.Background(), pluginDef, pluginSetting.OrgID)
|
||||
du.syncPluginDashboards(serviceCtx, pluginDef, pluginSetting.OrgID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestDashboardUpdater(t *testing.T) {
|
||||
t.Run("updateAppDashboards", func(t *testing.T) {
|
||||
scenario(t, "Without any stored plugin settings shouldn't delete/import any dashboards",
|
||||
scenarioInput{}, func(ctx *scenarioContext) {
|
||||
ctx.dashboardUpdater.updateAppDashboards()
|
||||
ctx.dashboardUpdater.updateAppDashboards(context.Background())
|
||||
|
||||
require.Len(t, ctx.pluginSettingsService.getPluginSettingsArgs, 1)
|
||||
require.Equal(t, int64(0), ctx.pluginSettingsService.getPluginSettingsArgs[0])
|
||||
@@ -46,7 +46,7 @@ func TestDashboardUpdater(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}, func(ctx *scenarioContext) {
|
||||
ctx.dashboardUpdater.updateAppDashboards()
|
||||
ctx.dashboardUpdater.updateAppDashboards(context.Background())
|
||||
|
||||
require.NotEmpty(t, ctx.pluginSettingsService.getPluginSettingsArgs)
|
||||
require.Empty(t, ctx.dashboardService.deleteDashboardArgs)
|
||||
@@ -68,7 +68,7 @@ func TestDashboardUpdater(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}, func(ctx *scenarioContext) {
|
||||
ctx.dashboardUpdater.updateAppDashboards()
|
||||
ctx.dashboardUpdater.updateAppDashboards(context.Background())
|
||||
|
||||
require.NotEmpty(t, ctx.pluginSettingsService.getPluginSettingsArgs)
|
||||
require.Empty(t, ctx.dashboardService.deleteDashboardArgs)
|
||||
@@ -100,7 +100,7 @@ func TestDashboardUpdater(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}, func(ctx *scenarioContext) {
|
||||
ctx.dashboardUpdater.updateAppDashboards()
|
||||
ctx.dashboardUpdater.updateAppDashboards(context.Background())
|
||||
|
||||
require.NotEmpty(t, ctx.pluginSettingsService.getPluginSettingsArgs)
|
||||
require.Empty(t, ctx.dashboardService.deleteDashboardArgs)
|
||||
@@ -135,7 +135,7 @@ func TestDashboardUpdater(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}, func(ctx *scenarioContext) {
|
||||
ctx.dashboardUpdater.updateAppDashboards()
|
||||
ctx.dashboardUpdater.updateAppDashboards(context.Background())
|
||||
|
||||
require.NotEmpty(t, ctx.pluginSettingsService.getPluginSettingsArgs)
|
||||
require.Empty(t, ctx.dashboardService.deleteDashboardArgs)
|
||||
@@ -183,7 +183,7 @@ func TestDashboardUpdater(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}, func(ctx *scenarioContext) {
|
||||
ctx.dashboardUpdater.updateAppDashboards()
|
||||
ctx.dashboardUpdater.updateAppDashboards(context.Background())
|
||||
|
||||
require.NotEmpty(t, ctx.pluginSettingsService.getPluginSettingsArgs)
|
||||
require.Len(t, ctx.dashboardService.deleteDashboardArgs, 1)
|
||||
|
||||
Reference in New Issue
Block a user