Dashboards API: Add v2alpha2 (#108121)

* Dashboards API: Register v2alpha2 API

* Prepare conversion functions

* Fix test

* Move to the bottom the v2aplha2 until is ready

---------

Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com>
This commit is contained in:
Dominik Prokop
2025-07-16 12:22:50 +00:00
committed by GitHub
co-authored by Ivan Ortega
parent 2fcb86f031
commit b4738c57e4
33 changed files with 12818 additions and 157 deletions
+37 -9
View File
@@ -23,7 +23,8 @@ import (
internal "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard"
dashv0 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
dashv1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
dashv2 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
dashv2alpha1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
dashv2alpha2 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha2"
"github.com/grafana/grafana/apps/dashboard/pkg/migration"
"github.com/grafana/grafana/apps/dashboard/pkg/migration/conversion"
"github.com/grafana/grafana/pkg/apimachinery/identity"
@@ -158,16 +159,18 @@ func (b *DashboardsAPIBuilder) GetGroupVersions() []schema.GroupVersion {
if featuremgmt.AnyEnabled(b.features, featuremgmt.FlagDashboardNewLayouts) {
// If dashboards v2 is enabled, we want to use v2alpha1 as the default API version.
return []schema.GroupVersion{
dashv2.DashboardResourceInfo.GroupVersion(),
dashv2alpha1.DashboardResourceInfo.GroupVersion(),
dashv0.DashboardResourceInfo.GroupVersion(),
dashv1.DashboardResourceInfo.GroupVersion(),
dashv2alpha2.DashboardResourceInfo.GroupVersion(),
}
}
return []schema.GroupVersion{
dashv1.DashboardResourceInfo.GroupVersion(),
dashv0.DashboardResourceInfo.GroupVersion(),
dashv2.DashboardResourceInfo.GroupVersion(),
dashv2alpha1.DashboardResourceInfo.GroupVersion(),
dashv2alpha2.DashboardResourceInfo.GroupVersion(),
}
}
@@ -179,7 +182,11 @@ func (b *DashboardsAPIBuilder) InstallSchema(scheme *runtime.Scheme) error {
if err := dashv1.AddToScheme(scheme); err != nil {
return err
}
if err := dashv2.AddToScheme(scheme); err != nil {
if err := dashv2alpha1.AddToScheme(scheme); err != nil {
return err
}
if err := dashv2alpha2.AddToScheme(scheme); err != nil {
return err
}
@@ -391,7 +398,10 @@ func getDashboardProperties(obj runtime.Object) (string, string, error) {
case *dashv1.Dashboard:
title = d.Spec.GetNestedString(dashboardSpecTitle)
refresh = d.Spec.GetNestedString(dashboardSpecRefreshInterval)
case *dashv2.Dashboard:
case *dashv2alpha1.Dashboard:
title = d.Spec.Title
refresh = d.Spec.TimeSettings.AutoRefresh
case *dashv2alpha2.Dashboard:
title = d.Spec.Title
refresh = d.Spec.TimeSettings.AutoRefresh
default:
@@ -456,11 +466,28 @@ func (b *DashboardsAPIBuilder) UpdateAPIGroupInfo(apiGroupInfo *genericapiserver
// v2alpha1
if err := b.storageForVersion(apiGroupInfo, opts, largeObjects,
dashv2.DashboardResourceInfo,
dashv2alpha1.DashboardResourceInfo,
nil, // do not register library panel
func(obj runtime.Object, access *internal.DashboardAccess) (v runtime.Object, err error) {
dto := &dashv2.DashboardWithAccessInfo{}
dash, ok := obj.(*dashv2.Dashboard)
dto := &dashv2alpha1.DashboardWithAccessInfo{}
dash, ok := obj.(*dashv2alpha1.Dashboard)
if ok {
dto.Dashboard = *dash
}
if access != nil {
err = b.scheme.Convert(access, &dto.Access, nil)
}
return dto, err
}); err != nil {
return err
}
if err := b.storageForVersion(apiGroupInfo, opts, largeObjects,
dashv2alpha2.DashboardResourceInfo,
nil, // do not register library panel
func(obj runtime.Object, access *internal.DashboardAccess) (v runtime.Object, err error) {
dto := &dashv2alpha2.DashboardWithAccessInfo{}
dash, ok := obj.(*dashv2alpha2.Dashboard)
if ok {
dto.Dashboard = *dash
}
@@ -544,7 +571,8 @@ func (b *DashboardsAPIBuilder) GetOpenAPIDefinitions() common.GetOpenAPIDefiniti
return func(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
defs := dashv0.GetOpenAPIDefinitions(ref)
maps.Copy(defs, dashv1.GetOpenAPIDefinitions(ref))
maps.Copy(defs, dashv2.GetOpenAPIDefinitions(ref))
maps.Copy(defs, dashv2alpha1.GetOpenAPIDefinitions(ref))
maps.Copy(defs, dashv2alpha2.GetOpenAPIDefinitions(ref))
return defs
}
}
+8 -4
View File
@@ -13,7 +13,8 @@ import (
dashv0 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
dashv1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
dashv2 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
dashv2alpha1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
dashv2alpha2 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha2"
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/featuremgmt"
@@ -176,7 +177,8 @@ func TestDashboardAPIBuilder_GetGroupVersions(t *testing.T) {
expected: []schema.GroupVersion{
dashv1.DashboardResourceInfo.GroupVersion(),
dashv0.DashboardResourceInfo.GroupVersion(),
dashv2.DashboardResourceInfo.GroupVersion(),
dashv2alpha1.DashboardResourceInfo.GroupVersion(),
dashv2alpha2.DashboardResourceInfo.GroupVersion(),
},
},
{
@@ -187,7 +189,8 @@ func TestDashboardAPIBuilder_GetGroupVersions(t *testing.T) {
expected: []schema.GroupVersion{
dashv1.DashboardResourceInfo.GroupVersion(),
dashv0.DashboardResourceInfo.GroupVersion(),
dashv2.DashboardResourceInfo.GroupVersion(),
dashv2alpha1.DashboardResourceInfo.GroupVersion(),
dashv2alpha2.DashboardResourceInfo.GroupVersion(),
},
},
{
@@ -196,9 +199,10 @@ func TestDashboardAPIBuilder_GetGroupVersions(t *testing.T) {
featuremgmt.FlagDashboardNewLayouts,
},
expected: []schema.GroupVersion{
dashv2.DashboardResourceInfo.GroupVersion(),
dashv2alpha1.DashboardResourceInfo.GroupVersion(),
dashv0.DashboardResourceInfo.GroupVersion(),
dashv1.DashboardResourceInfo.GroupVersion(),
dashv2alpha2.DashboardResourceInfo.GroupVersion(),
},
},
}