Dashboard Migrations: V2 - legacy services.filter and graphite panel type (#112282)

* migrate to v2

* Fix tests

* graphite panels should be auto-migrated

* lint

* Provisioning: Fix dashboard export to preserve original API version

* Add error handling for the edge case where conversion fails but no
storedVersion is available.
This commit is contained in:
Haris Rozajac
2025-10-15 10:34:12 -06:00
committed by GitHub
parent 5b7e6ef2e1
commit d9067b27eb
13 changed files with 734 additions and 78 deletions
@@ -41,9 +41,11 @@ func ExportResources(ctx context.Context, options provisioning.ExportJobOptions,
if kind.GroupResource() == resources.DashboardResource.GroupResource() {
var v2clientAlphaV1, v2clientAlphaV2 dynamic.ResourceInterface
shim = func(ctx context.Context, item *unstructured.Unstructured) (*unstructured.Unstructured, error) {
failed, _, _ := unstructured.NestedBool(item.Object, "status", "conversion", "failed")
if failed {
storedVersion, _, _ := unstructured.NestedString(item.Object, "status", "conversion", "storedVersion")
// Check if there's a stored version in the conversion status.
// This indicates the original API version the dashboard was created with,
// which should be preserved during export regardless of whether conversion succeeded or failed.
storedVersion, _, _ := unstructured.NestedString(item.Object, "status", "conversion", "storedVersion")
if storedVersion != "" {
// For v2 we need to request the original version
if strings.HasPrefix(storedVersion, "v2alpha1") {
if v2clientAlphaV1 == nil {
@@ -73,6 +75,13 @@ func ExportResources(ctx context.Context, options provisioning.ExportJobOptions,
return nil, fmt.Errorf("unsupported dashboard version: %s", storedVersion)
}
// If conversion failed but there's no storedVersion, this is an error condition
failed, _, _ := unstructured.NestedBool(item.Object, "status", "conversion", "failed")
if failed {
return nil, fmt.Errorf("conversion failed but no storedVersion available")
}
return item, nil
}
}