Provisioning: Add k8s annotations for legacy folder provisioning (#110827)
This commit is contained in:
@@ -37,6 +37,14 @@ func LegacyCreateCommandToUnstructured(cmd *folder.CreateFolderCommand) (*unstru
|
||||
meta.SetName(cmd.UID)
|
||||
meta.SetFolder(cmd.ParentUID)
|
||||
|
||||
// nolint:staticcheck
|
||||
if cmd.ManagerKindClassicFP != "" {
|
||||
meta.SetManagerProperties(utils.ManagerProperties{
|
||||
Kind: utils.ManagerKindClassicFP,
|
||||
Identity: cmd.ManagerKindClassicFP,
|
||||
})
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ type DashboardProvisioningService interface {
|
||||
GetProvisionedDashboardData(ctx context.Context, name string) ([]*DashboardProvisioning, error)
|
||||
GetProvisionedDashboardDataByDashboardID(ctx context.Context, dashboardID int64) (*DashboardProvisioning, error)
|
||||
GetProvisionedDashboardDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*DashboardProvisioning, error)
|
||||
SaveFolderForProvisionedDashboards(context.Context, *folder.CreateFolderCommand) (*folder.Folder, error)
|
||||
SaveFolderForProvisionedDashboards(ctx context.Context, cmd *folder.CreateFolderCommand, readerName string) (*folder.Folder, error)
|
||||
SaveProvisionedDashboard(ctx context.Context, dto *SaveDashboardDTO, provisioning *DashboardProvisioning) (*Dashboard, error)
|
||||
UnprovisionDashboard(ctx context.Context, dashboardID int64) error
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ package dashboards
|
||||
import (
|
||||
context "context"
|
||||
|
||||
folder "github.com/grafana/grafana/pkg/services/folder"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
folder "github.com/grafana/grafana/pkg/services/folder"
|
||||
)
|
||||
|
||||
// FakeDashboardProvisioning is an autogenerated mock type for the DashboardProvisioningService type
|
||||
@@ -141,7 +142,7 @@ func (_m *FakeDashboardProvisioning) GetProvisionedDashboardDataByDashboardUID(c
|
||||
}
|
||||
|
||||
// SaveFolderForProvisionedDashboards provides a mock function with given fields: _a0, _a1
|
||||
func (_m *FakeDashboardProvisioning) SaveFolderForProvisionedDashboards(_a0 context.Context, _a1 *folder.CreateFolderCommand) (*folder.Folder, error) {
|
||||
func (_m *FakeDashboardProvisioning) SaveFolderForProvisionedDashboards(_a0 context.Context, _a1 *folder.CreateFolderCommand, _ string) (*folder.Folder, error) {
|
||||
ret := _m.Called(_a0, _a1)
|
||||
|
||||
if len(ret) == 0 {
|
||||
|
||||
@@ -971,13 +971,16 @@ func (dr *DashboardServiceImpl) SaveProvisionedDashboard(ctx context.Context, dt
|
||||
return dash, nil
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) SaveFolderForProvisionedDashboards(ctx context.Context, dto *folder.CreateFolderCommand) (*folder.Folder, error) {
|
||||
func (dr *DashboardServiceImpl) SaveFolderForProvisionedDashboards(ctx context.Context, dto *folder.CreateFolderCommand, readerName string) (*folder.Folder, error) {
|
||||
ctx, span := tracer.Start(ctx, "dashboards.service.SaveFolderForProvisionedDashboards")
|
||||
defer span.End()
|
||||
|
||||
ctx, ident := identity.WithServiceIdentity(ctx, dto.OrgID)
|
||||
dto.SignedInUser = ident
|
||||
|
||||
// The readerName is the identifier for the file provisioning manager
|
||||
dto.ManagerKindClassicFP = readerName // nolint:staticcheck
|
||||
|
||||
f, err := dr.folderService.Create(ctx, dto)
|
||||
if err != nil {
|
||||
dr.log.Error("failed to create folder for provisioned dashboards", "folder", dto.Title, "org", dto.OrgID, "err", err)
|
||||
|
||||
@@ -1078,7 +1078,7 @@ func TestSetDefaultPermissionsWhenSavingFolderForProvisionedDashboards(t *testin
|
||||
}
|
||||
|
||||
service.features = featuremgmt.WithFeatures()
|
||||
folder, err := service.SaveFolderForProvisionedDashboards(context.Background(), cmd)
|
||||
folder, err := service.SaveFolderForProvisionedDashboards(context.Background(), cmd, "")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, folder)
|
||||
|
||||
|
||||
@@ -511,6 +511,8 @@ func (s *Service) createOnApiServer(ctx context.Context, cmd *folder.CreateFolde
|
||||
Description: cmd.Description,
|
||||
ParentUID: cmd.ParentUID,
|
||||
SignedInUser: cmd.SignedInUser,
|
||||
// pass along provisioning details
|
||||
ManagerKindClassicFP: cmd.ManagerKindClassicFP, // nolint:staticcheck
|
||||
}
|
||||
|
||||
f, err := s.unifiedStore.Create(ctx, *cmd)
|
||||
|
||||
@@ -132,6 +132,13 @@ type CreateFolderCommand struct {
|
||||
ParentUID string `json:"parentUid"`
|
||||
|
||||
SignedInUser identity.Requester `json:"-"`
|
||||
|
||||
// When running classic file provisioning with folders saved in kubernetes,
|
||||
// folders will be marked with a manager of kind ManagerKindClassicFP
|
||||
// NOTE: this is ignored when running legacy SQL storage
|
||||
//
|
||||
// Deprecated: this should only be used by the legacy file provisioning system
|
||||
ManagerKindClassicFP string `json:"-"`
|
||||
}
|
||||
|
||||
// UpdateFolderCommand captures the information required by the folder service
|
||||
|
||||
@@ -147,7 +147,7 @@ func (prov *defaultAlertRuleProvisioner) getOrCreateFolderByTitle(
|
||||
createCmd.ParentUID = *parentUID
|
||||
}
|
||||
|
||||
f, err := prov.dashboardProvService.SaveFolderForProvisionedDashboards(ctx, createCmd)
|
||||
f, err := prov.dashboardProvService.SaveFolderForProvisionedDashboards(ctx, createCmd, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func New(ctx context.Context, configDirectory string, provisioner dashboards.Das
|
||||
}
|
||||
|
||||
if dual != nil && !dual.ShouldManage(dashboard.DashboardResourceInfo.GroupResource()) {
|
||||
dual = nil // not activily managed
|
||||
dual = nil // not actively managed
|
||||
}
|
||||
|
||||
d := &Provisioner{
|
||||
|
||||
@@ -391,7 +391,7 @@ func (fr *FileReader) getOrCreateFolder(ctx context.Context, cfg *config, servic
|
||||
SignedInUser: user,
|
||||
}
|
||||
|
||||
f, err := service.SaveFolderForProvisionedDashboards(ctx, createCmd)
|
||||
f, err := service.SaveFolderForProvisionedDashboards(ctx, createCmd, fr.Cfg.Name)
|
||||
if err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user