* Deprecate Legacy Storage Migration in Backend * Change the messaging around legacy storage * Disable cards to connect * Commit import changes * Block repository creation if resources are in legacy storage * Update error message * Prettify * chore: uncomment unified migration * chore: adapt and fix tests * Remove legacy storage migration from frontend * Refactor provisioning job options by removing legacy storage and history fields - Removed the `History` field from `MigrateJobOptions` and related references in the codebase. - Eliminated the `LegacyStorage` field from `RepositoryViewList` and its associated comments. - Updated tests and generated OpenAPI schema to reflect these changes. - Simplified the `MigrationWorker` by removing dependencies on legacy storage checks. * Refactor OpenAPI schema and tests to remove deprecated fields - Removed the `history` field from `MigrateJobOptions` and updated the OpenAPI schema accordingly. - Eliminated the `legacyStorage` field from `RepositoryViewList` and its associated comments in the schema. - Updated integration tests to reflect the removal of these fields. * Fix typescript errors * Refactor provisioning code to remove legacy storage dependencies - Eliminated references to `dualwrite.Service` and related legacy storage checks across multiple files. - Updated `APIBuilder`, `RepositoryController`, and `SyncWorker` to streamline resource handling without legacy storage considerations. - Adjusted tests to reflect the removal of legacy storage mocks and dependencies, ensuring cleaner and more maintainable code. * Fix unit tests * Remove more references to legacy * Enhance provisioning wizard with migration options - Added a checkbox for migrating existing resources in the BootstrapStep component. - Updated the form context to track the new migration option. - Adjusted the SynchronizeStep and useCreateSyncJob hook to incorporate the migration logic. - Enhanced localization with new descriptions and labels for migration features. * Remove unused variable and dualwrite reference in provisioning code - Eliminated an unused variable declaration in `provisioning_manifest.go`. - Removed the `nil` reference for dualwrite in `repo_operator.go`, aligning with the standalone operator's assumption of unified storage. * Update go.mod and go.sum to include new dependencies - Added `github.com/grafana/grafana-app-sdk` version `0.48.5` and several indirect dependencies including `github.com/getkin/kin-openapi`, `github.com/hashicorp/errwrap`, and others. - Updated `go.sum` to reflect the new dependencies and their respective versions. * Refactor provisioning components for improved readability - Simplified the import statement in HomePage.tsx by removing unnecessary line breaks. - Consolidated props in the SynchronizeStep component for cleaner code. - Enhanced the layout of the ProvisioningWizard component by streamlining the rendering of the SynchronizeStep. * Deprecate MigrationWorker and clean up related comments - Removed the deprecated MigrationWorker implementation and its associated comments from the provisioning code. - This change reflects the ongoing effort to eliminate legacy components and improve code maintainability. * Fix linting issues * Add explicit comment * Update useResourceStats hook in BootstrapStep component to accept selected target - Modified the BootstrapStep component to pass the selected target to the useResourceStats hook. - Updated related tests to reflect the change in expected arguments for the useResourceStats hook. * fix(provisioning): Update migrate tests to match export-then-sync behavior for all repository types Updates test expectations for folder-type repositories to match the implementation changes where both folder and instance repository types now run export followed by sync. Only the namespace cleaner is skipped for folder-type repositories. Changes: - Update "should run export and sync for folder-type repositories" test to include export mocks - Update "should fail when sync job fails for folder-type repositories" test to include export mocks - Rename test to clarify that both export and sync run for folder types - Add proper mock expectations for SetMessage, StrictMaxErrors, Process, and ResetResults All migrate package tests now pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Update provisioning wizard text and improve resource counting display - Enhanced descriptions for migrating existing resources to clarify that unmanaged resources will also be included. - Refactored BootstrapStepResourceCounting component to simplify the rendering logic and ensure both external storage and unmanaged resources are displayed correctly. - Updated alert messages in SynchronizeStep to reflect accurate information regarding resource management during migration. - Adjusted localization strings for consistency with the new descriptions. * Update provisioning wizard alert messages for clarity and accuracy - Revised alert points to indicate that resources can still be modified during migration, with a note on potential export issues. - Clarified that resources will be marked as managed post-provisioning and that dashboards remain accessible throughout the process. * Fix issue with trigger wrong type of job * Fix export failure when folder already exists in repository When exporting resources to a repository, if a folder already exists, the Read() method would fail with "path component is empty" error. This occurred because: 1. Folders are identified by trailing slash (e.g., "Legacy Folder/") 2. The Read() method passes this path directly to GetTreeByPath() 3. GetTreeByPath() splits the path by "/" creating empty components 4. This causes the "path component is empty" error The fix strips the trailing slash before calling GetTreeByPath() to avoid empty path components, while still using the trailing slash convention to identify directories. The Create() method already handles this correctly by appending ".keep" to directory paths, which is why the first export succeeded but subsequent exports failed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Fix folder tree not updated when folder already exists in repository When exporting resources and a folder already exists in the repository, the folder was not being added to the FolderManager's tree. This caused subsequent dashboard exports to fail with "folder NOT found in tree". The fix adds the folder to fm.tree even when it already exists in the repository, ensuring all folders are available for resource lookups. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Revert "Merge remote-tracking branch 'origin/uncomment-unified-migration-code' into cleanup/deprecate-legacy-storage-migration-in-provisioning" This reverts commit6440fae342, reversing changes made toec39fb04f2. * fix: handle empty folder titles in path construction - Skip folders with empty titles in dirPath to avoid empty path components - Skip folders with empty paths before checking if they exist in repository - Fix unit tests to properly check useResourceStats hook calls with type annotations * Update workspace * Fix BootstrapStep tests after reverting unified migration merge Updated test expectations to match the current component behavior where resource counts are displayed for both instance and folder sync options. - Changed 'Empty' count expectation from 3 to 4 (2 cards × 2 counts each) - Changed '7 resources' test to use findAllByText instead of findByText since the count appears in multiple cards 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Remove bubbletee deps * Fix workspace * provisioning: update error message to reference enableMigration config Update the error message when provisioning cannot be used due to incompatible data format to instruct users to enable data migration for folders and dashboards using the enableMigration configuration introduced in PR #114857. Also update the test helper to include EnableMigration: true for both dashboards and folders to match the new configuration pattern. * provisioning: add comment explaining Mode5 and EnableMigration requirement Add a comment in the integration test helper explaining that Provisioning requires Mode5 (unified storage) and EnableMigration (data migration) as it expects resources to be fully migrated to unified storage. * Remove migrate resources checkbox from folder type provisioning wizard - Remove checkbox UI for migrating existing resources in folder type - Remove migrateExistingResources from migration logic - Simplify migration to only use requiresMigration flag - Remove unused translation keys - Update i18n strings * Fix linting * Remove unnecessary React Fragment wrapper in BootstrapStep * Address comments --------- Co-authored-by: Rafael Paulovic <rafael.paulovic@grafana.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
141 lines
4.0 KiB
Go
141 lines
4.0 KiB
Go
package apis
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
"k8s.io/apimachinery/pkg/util/version"
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"github.com/grafana/grafana/pkg/apiserver/rest"
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/grafana/grafana/pkg/tests/testinfra"
|
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
|
"github.com/grafana/grafana/pkg/util/testutil"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
testsuite.Run(m)
|
|
}
|
|
|
|
func TestIntegrationOpenAPIs(t *testing.T) {
|
|
testutil.SkipIntegrationTestInShortMode(t)
|
|
|
|
h := NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
|
AppModeProduction: false, // required for experimental APIs
|
|
EnableFeatureToggles: []string{
|
|
featuremgmt.FlagQueryService, // Query Library
|
|
featuremgmt.FlagProvisioning,
|
|
featuremgmt.FlagInvestigationsBackend,
|
|
featuremgmt.FlagGrafanaAdvisor,
|
|
featuremgmt.FlagKubernetesAlertingRules,
|
|
featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // all datasources
|
|
featuremgmt.FlagKubernetesShortURLs,
|
|
featuremgmt.FlagKubernetesCorrelations,
|
|
featuremgmt.FlagKubernetesAlertingHistorian,
|
|
featuremgmt.FlagKubernetesLogsDrilldown,
|
|
},
|
|
// Explicitly configure with mode 5 the resources supported by provisioning.
|
|
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
|
"dashboards.dashboard.grafana.app": {DualWriterMode: rest.Mode5},
|
|
"folders.folder.grafana.app": {DualWriterMode: rest.Mode5},
|
|
},
|
|
})
|
|
|
|
t.Run("check valid version response", func(t *testing.T) {
|
|
client, err := kubernetes.NewForConfig(h.NewAdminRestConfig())
|
|
require.NoError(t, err)
|
|
|
|
info, err := client.ServerVersion()
|
|
require.NoError(t, err)
|
|
require.Equal(t, runtime.Version(), info.GoVersion)
|
|
require.Equal(t, "1", info.Major)
|
|
require.Equal(t, "34", info.Minor)
|
|
|
|
// Make sure the gitVersion is parsable
|
|
v, err := version.Parse(info.GitVersion)
|
|
require.NoError(t, err)
|
|
require.Equal(t, info.Major, fmt.Sprintf("%d", v.Major()))
|
|
require.Equal(t, info.Minor, fmt.Sprintf("%d", v.Minor()))
|
|
|
|
// Check the v3 path resolves properly
|
|
// NOTE: fetching the v2 schema sometimes returns a 503 in our test infrastructure
|
|
// Removing the explicit `OneOf` properties from InlineSecureValue in:
|
|
// https://github.com/grafana/grafana/blob/main/pkg/apimachinery/apis/common/v0alpha1/secure_values.go#L78
|
|
// will consistently support V2, however kubectl and everything else continues to work
|
|
disco := h.NewDiscoveryClient()
|
|
paths, err := disco.OpenAPIV3().Paths()
|
|
|
|
require.NoError(t, err, "requesting OpenAPI v3")
|
|
require.NotEmpty(t, paths, "has registered paths")
|
|
})
|
|
|
|
dir := "openapi_snapshots"
|
|
|
|
var groups = []schema.GroupVersion{{
|
|
Group: "dashboard.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "dashboard.grafana.app",
|
|
Version: "v1beta1",
|
|
}, {
|
|
Group: "dashboard.grafana.app",
|
|
Version: "v2alpha1",
|
|
}, {
|
|
Group: "dashboard.grafana.app",
|
|
Version: "v2beta1",
|
|
}, {
|
|
Group: "folder.grafana.app",
|
|
Version: "v1beta1",
|
|
}, {
|
|
Group: "provisioning.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "iam.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "investigations.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "advisor.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "playlist.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "preferences.grafana.app",
|
|
Version: "v1alpha1",
|
|
}, {
|
|
Group: "collections.grafana.app",
|
|
Version: "v1alpha1",
|
|
}, {
|
|
Group: "notifications.alerting.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "rules.alerting.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "historian.alerting.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "correlations.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "shorturl.grafana.app",
|
|
Version: "v1beta1",
|
|
}, {
|
|
Group: "testdata.datasource.grafana.app",
|
|
Version: "v0alpha1",
|
|
}, {
|
|
Group: "logsdrilldown.grafana.app",
|
|
Version: "v1alpha1",
|
|
}}
|
|
for _, gv := range groups {
|
|
VerifyOpenAPISnapshots(t, dir, gv, h)
|
|
}
|
|
}
|