Dashboard: Transform v2alpha1 to v1beta1 (#114024)
Co-authored-by: Haris Rozajac <haris.rozajac12@gmail.com>
This commit is contained in:
co-authored by
Haris Rozajac
parent
8ff75c2177
commit
39d0dbeddc
@@ -8,10 +8,13 @@ import (
|
||||
dashv1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
|
||||
dashv2alpha1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
|
||||
dashv2beta1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2beta1"
|
||||
"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
|
||||
|
||||
@@ -27,17 +30,31 @@ func Convert_V2alpha1_to_V0(in *dashv2alpha1.Dashboard, out *dashv0.Dashboard, s
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_V2alpha1_to_V1beta1(in *dashv2alpha1.Dashboard, out *dashv1.Dashboard, scope conversion.Scope) error {
|
||||
func Convert_V2alpha1_to_V1beta1(in *dashv2alpha1.Dashboard, out *dashv1.Dashboard, scope conversion.Scope, dsIndexProvider schemaversion.DataSourceIndexProvider) error {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv1.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
|
||||
// TODO: implement V2 to V1 conversion
|
||||
// Convert the spec
|
||||
if err := ConvertDashboard_V2alpha1_to_V1beta1(in, out, scope, dsIndexProvider); err != nil {
|
||||
out.Status = dashv1.DashboardStatus{
|
||||
Conversion: &dashv1.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2alpha1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To(err.Error()),
|
||||
Source: in,
|
||||
},
|
||||
}
|
||||
|
||||
// For errors, set status but don't return error (matches v1beta1_to_v2alpha1 pattern)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Set successful conversion status
|
||||
out.Status = dashv1.DashboardStatus{
|
||||
Conversion: &dashv1.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2alpha1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To("backend conversion not yet implemented"),
|
||||
Source: in,
|
||||
Failed: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -46,6 +63,8 @@ func Convert_V2alpha1_to_V1beta1(in *dashv2alpha1.Dashboard, out *dashv1.Dashboa
|
||||
|
||||
func Convert_V2alpha1_to_V2beta1(in *dashv2alpha1.Dashboard, out *dashv2beta1.Dashboard, scope conversion.Scope) error {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv2beta1.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
|
||||
// Convert the spec
|
||||
if err := ConvertDashboard_V2alpha1_to_V2beta1(in, out, scope); err != nil {
|
||||
@@ -74,6 +93,8 @@ func Convert_V2alpha1_to_V2beta1(in *dashv2alpha1.Dashboard, out *dashv2beta1.Da
|
||||
|
||||
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
|
||||
|
||||
@@ -89,17 +110,48 @@ func Convert_V2beta1_to_V0(in *dashv2beta1.Dashboard, out *dashv0.Dashboard, sco
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_V2beta1_to_V1beta1(in *dashv2beta1.Dashboard, out *dashv1.Dashboard, scope conversion.Scope) error {
|
||||
func Convert_V2beta1_to_V1beta1(in *dashv2beta1.Dashboard, out *dashv1.Dashboard, scope conversion.Scope, dsIndexProvider schemaversion.DataSourceIndexProvider) error {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv1.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
|
||||
// TODO: implement v2beta1 to V1 conversion
|
||||
// Convert v2beta1 → v2alpha1 first, then v2alpha1 → v1beta1
|
||||
// This combines the atomic conversions, similar to Convert_V1beta1_to_V2beta1
|
||||
v2alpha1 := &dashv2alpha1.Dashboard{}
|
||||
if err := ConvertDashboard_V2beta1_to_V2alpha1(in, v2alpha1, scope); err != nil {
|
||||
out.Status = dashv1.DashboardStatus{
|
||||
Conversion: &dashv1.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2beta1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To(err.Error()),
|
||||
Source: in,
|
||||
},
|
||||
}
|
||||
// For errors, set status but don't return error (matches v1beta1_to_v2alpha1 pattern)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert v2alpha1 → v1beta1
|
||||
// Note: ConvertDashboard_V2alpha1_to_V1beta1 will set out.ObjectMeta from v2alpha1,
|
||||
// but we've already set it from the original input, so it will be preserved
|
||||
if err := ConvertDashboard_V2alpha1_to_V1beta1(v2alpha1, out, scope, dsIndexProvider); err != nil {
|
||||
out.Status = dashv1.DashboardStatus{
|
||||
Conversion: &dashv1.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2beta1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To(err.Error()),
|
||||
Source: in,
|
||||
},
|
||||
}
|
||||
// For errors, set status but don't return error (matches v1beta1_to_v2alpha1 pattern)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Set successful conversion status
|
||||
out.Status = dashv1.DashboardStatus{
|
||||
Conversion: &dashv1.DashboardConversionStatus{
|
||||
StoredVersion: ptr.To(dashv2beta1.VERSION),
|
||||
Failed: true,
|
||||
Error: ptr.To("backend conversion not yet implemented"),
|
||||
Source: in,
|
||||
Failed: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -108,6 +160,8 @@ func Convert_V2beta1_to_V1beta1(in *dashv2beta1.Dashboard, out *dashv1.Dashboard
|
||||
|
||||
func Convert_V2beta1_to_V2alpha1(in *dashv2beta1.Dashboard, out *dashv2alpha1.Dashboard, scope conversion.Scope) error {
|
||||
out.ObjectMeta = in.ObjectMeta
|
||||
out.APIVersion = dashv2alpha1.APIVERSION
|
||||
out.Kind = in.Kind
|
||||
|
||||
if err := ConvertDashboard_V2beta1_to_V2alpha1(in, out, scope); err != nil {
|
||||
out.Status = dashv2alpha1.DashboardStatus{
|
||||
|
||||
Reference in New Issue
Block a user