Dashboard migration: Implement v2 to v0 conversions (#114812)
* Update docs * Remove 406 response since now it is converted * fix linter --------- Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
This commit is contained in:
co-authored by
Stephanie Hingtgen
parent
dcd2086212
commit
c8853f50cf
@@ -11,22 +11,45 @@ import (
|
||||
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
||||
)
|
||||
|
||||
func Convert_V2alpha1_to_V0(in *dashv2alpha1.Dashboard, out *dashv0.Dashboard, scope conversion.Scope) error {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv0.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
|
||||
// TODO: implement V2 to V0 conversion
|
||||
|
||||
out.Status = dashv0.DashboardStatus{
|
||||
Conversion: &dashv0.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2alpha1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To("backend conversion not yet implemented"),
|
||||
Source: in,
|
||||
},
|
||||
func Convert_V2alpha1_to_V0(in *dashv2alpha1.Dashboard, out *dashv0.Dashboard, scope conversion.Scope, dsIndexProvider schemaversion.DataSourceIndexProvider) error {
|
||||
// Convert v2alpha1 → v1beta1 first, then v1beta1 → v0
|
||||
v1beta1 := &dashv1.Dashboard{}
|
||||
if err := ConvertDashboard_V2alpha1_to_V1beta1(in, v1beta1, scope, dsIndexProvider); err != nil {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv0.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
out.Status = dashv0.DashboardStatus{
|
||||
Conversion: &dashv0.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2alpha1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To(err.Error()),
|
||||
Source: in,
|
||||
},
|
||||
}
|
||||
// For errors, set status but don't return error
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert v1beta1 → v0
|
||||
if err := Convert_V1beta1_to_V0(v1beta1, out, scope); err != nil {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv0.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
out.Status = dashv0.DashboardStatus{
|
||||
Conversion: &dashv0.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2alpha1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To(err.Error()),
|
||||
Source: in,
|
||||
},
|
||||
}
|
||||
// For errors, set status but don't return error
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update the stored version to reflect the original source
|
||||
out.Status.Conversion.StoredVersion = ptr.To(dashv2alpha1.VERSION)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -46,7 +69,7 @@ func Convert_V2alpha1_to_V1beta1(in *dashv2alpha1.Dashboard, out *dashv1.Dashboa
|
||||
},
|
||||
}
|
||||
|
||||
// For errors, set status but don't return error (matches v1beta1_to_v2alpha1 pattern)
|
||||
// For errors, set status but don't return error
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -91,22 +114,44 @@ func Convert_V2alpha1_to_V2beta1(in *dashv2alpha1.Dashboard, out *dashv2beta1.Da
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_V2beta1_to_V0(in *dashv2beta1.Dashboard, out *dashv0.Dashboard, scope conversion.Scope) error {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv0.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
|
||||
// TODO: implement v2beta1 to V0 conversion
|
||||
|
||||
out.Status = dashv0.DashboardStatus{
|
||||
Conversion: &dashv0.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2beta1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To("backend conversion not yet implemented"),
|
||||
Source: in,
|
||||
},
|
||||
func Convert_V2beta1_to_V0(in *dashv2beta1.Dashboard, out *dashv0.Dashboard, scope conversion.Scope, dsIndexProvider schemaversion.DataSourceIndexProvider) error {
|
||||
// Convert v2beta1 → v1beta1 first, then v1beta1 → v0
|
||||
v1beta1 := &dashv1.Dashboard{}
|
||||
if err := Convert_V2beta1_to_V1beta1(in, v1beta1, scope, dsIndexProvider); err != nil {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv0.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
out.Status = dashv0.DashboardStatus{
|
||||
Conversion: &dashv0.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2beta1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To(err.Error()),
|
||||
Source: in,
|
||||
},
|
||||
}
|
||||
// For errors, set status but don't return error
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert v1beta1 → v0
|
||||
if err := Convert_V1beta1_to_V0(v1beta1, out, scope); err != nil {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv0.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
out.Status = dashv0.DashboardStatus{
|
||||
Conversion: &dashv0.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2beta1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To(err.Error()),
|
||||
Source: in,
|
||||
},
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update the stored version to reflect the original source
|
||||
out.Status.Conversion.StoredVersion = ptr.To(dashv2beta1.VERSION)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -127,7 +172,7 @@ func Convert_V2beta1_to_V1beta1(in *dashv2beta1.Dashboard, out *dashv1.Dashboard
|
||||
Source: in,
|
||||
},
|
||||
}
|
||||
// For errors, set status but don't return error (matches v1beta1_to_v2alpha1 pattern)
|
||||
// For errors, set status but don't return error
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -143,7 +188,7 @@ func Convert_V2beta1_to_V1beta1(in *dashv2beta1.Dashboard, out *dashv1.Dashboard
|
||||
Source: in,
|
||||
},
|
||||
}
|
||||
// For errors, set status but don't return error (matches v1beta1_to_v2alpha1 pattern)
|
||||
// For errors, set status but don't return error
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user