K8s/Dashboard: Promote from alpha1 to beta1 (#104009)

This commit is contained in:
Ryan McKinley
2025-04-23 20:54:35 +03:00
committed by GitHub
parent a6866176cd
commit b09d79b21c
84 changed files with 532 additions and 517 deletions
+13 -13
View File
@@ -20,7 +20,7 @@ import (
"github.com/grafana/grafana/pkg/tests/testsuite"
dashboardV0 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
dashboardV1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1alpha1"
dashboardV1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
dashboardV2 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
)
@@ -112,8 +112,8 @@ func runDashboardTest(t *testing.T, helper *apis.K8sTestHelper, gvr schema.Group
func TestIntegrationDashboardsAppV0Alpha1(t *testing.T) {
gvr := schema.GroupVersionResource{
Group: "dashboard.grafana.app",
Version: "v0alpha1",
Group: dashboardV1.GROUP,
Version: dashboardV1.VERSION,
Resource: "dashboards",
}
if testing.Short() {
@@ -182,17 +182,17 @@ func TestIntegrationDashboardsAppV0Alpha1(t *testing.T) {
})
}
func TestIntegrationDashboardsAppV1Alpha1(t *testing.T) {
func TestIntegrationDashboardsAppV1(t *testing.T) {
gvr := schema.GroupVersionResource{
Group: "dashboard.grafana.app",
Version: "v1alpha1",
Group: dashboardV1.GROUP,
Version: dashboardV1.VERSION,
Resource: "dashboards",
}
if testing.Short() {
t.Skip("skipping integration test")
}
t.Run("v1alpha1 with dual writer mode 0", func(t *testing.T) {
t.Run("v1 with dual writer mode 0", func(t *testing.T) {
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
DisableAnonymous: true,
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
@@ -204,7 +204,7 @@ func TestIntegrationDashboardsAppV1Alpha1(t *testing.T) {
runDashboardTest(t, helper, gvr)
})
t.Run("v1alpha1 with dual writer mode 1", func(t *testing.T) {
t.Run("v1 with dual writer mode 1", func(t *testing.T) {
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
DisableAnonymous: true,
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
@@ -216,7 +216,7 @@ func TestIntegrationDashboardsAppV1Alpha1(t *testing.T) {
runDashboardTest(t, helper, gvr)
})
t.Run("v1alpha1 with dual writer mode 2", func(t *testing.T) {
t.Run("v1 with dual writer mode 2", func(t *testing.T) {
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
DisableAnonymous: true,
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
@@ -228,7 +228,7 @@ func TestIntegrationDashboardsAppV1Alpha1(t *testing.T) {
runDashboardTest(t, helper, gvr)
})
t.Run("v1alpha1 with dual writer mode 3", func(t *testing.T) {
t.Run("v1 with dual writer mode 3", func(t *testing.T) {
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
DisableAnonymous: true,
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
@@ -240,7 +240,7 @@ func TestIntegrationDashboardsAppV1Alpha1(t *testing.T) {
runDashboardTest(t, helper, gvr)
})
t.Run("v1alpha1 with dual writer mode 4", func(t *testing.T) {
t.Run("v1 with dual writer mode 4", func(t *testing.T) {
t.Skip("skipping test because of authorizer issue")
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
DisableAnonymous: true,
@@ -343,14 +343,14 @@ func TestIntegrationLegacySupport(t *testing.T) {
Path: "/api/dashboards/uid/test-v0",
}, &dtos.DashboardFullWithMeta{})
require.Equal(t, 200, rsp.Response.StatusCode)
require.Equal(t, "v0alpha1", rsp.Result.Meta.APIVersion)
require.Equal(t, dashboardV0.VERSION, rsp.Result.Meta.APIVersion)
rsp = apis.DoRequest(helper, apis.RequestParams{
User: helper.Org1.Admin,
Path: "/api/dashboards/uid/test-v1",
}, &dtos.DashboardFullWithMeta{})
require.Equal(t, 200, rsp.Response.StatusCode)
require.Equal(t, "v0alpha1", rsp.Result.Meta.APIVersion) // v0alpha1 is used as the default version for /api
require.Equal(t, dashboardV0.VERSION, rsp.Result.Meta.APIVersion)
// V2 should send a not acceptable
rsp = apis.DoRequest(helper, apis.RequestParams{
@@ -9,10 +9,15 @@ import (
"strings"
"testing"
dashboardv0alpha1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
dashboardv1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1alpha1"
dashboardv2alpha1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
folders "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
dashboardV0 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
dashboardV1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
dashboardV2 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
foldersV1 "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
"github.com/grafana/grafana/pkg/apiserver/rest"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/folder"
@@ -21,10 +26,6 @@ import (
"github.com/grafana/grafana/pkg/tests/apis"
"github.com/grafana/grafana/pkg/tests/testinfra"
"github.com/grafana/grafana/pkg/tests/testsuite"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/apimachinery/utils"
@@ -258,11 +259,11 @@ func runDashboardValidationTests(t *testing.T, ctx TestContext) {
}{
{
name: "v0alpha1 dashboard with wrong spec should not throw on v0",
resourceInfo: dashboardv0alpha1.DashboardResourceInfo,
resourceInfo: dashboardV0.DashboardResourceInfo,
expectSpecErr: false,
testObject: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": dashboardv0alpha1.DashboardResourceInfo.TypeMeta().APIVersion,
"apiVersion": dashboardV0.DashboardResourceInfo.TypeMeta().APIVersion,
"kind": "Dashboard",
"metadata": map[string]interface{}{
"generateName": "test-",
@@ -279,11 +280,11 @@ func runDashboardValidationTests(t *testing.T, ctx TestContext) {
},
{
name: "v1 dashboard with wrong spec should throw on v1",
resourceInfo: dashboardv1.DashboardResourceInfo,
resourceInfo: dashboardV1.DashboardResourceInfo,
expectSpecErr: true,
testObject: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": dashboardv1.DashboardResourceInfo.TypeMeta().APIVersion,
"apiVersion": dashboardV1.DashboardResourceInfo.TypeMeta().APIVersion,
"kind": "Dashboard",
"metadata": map[string]interface{}{
"generateName": "test-",
@@ -300,11 +301,11 @@ func runDashboardValidationTests(t *testing.T, ctx TestContext) {
},
{
name: "v2alpha1 dashboard with correct spec should not throw on v2",
resourceInfo: dashboardv2alpha1.DashboardResourceInfo,
resourceInfo: dashboardV2.DashboardResourceInfo,
expectSpecErr: false,
testObject: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": dashboardv2alpha1.DashboardResourceInfo.TypeMeta().APIVersion,
"apiVersion": dashboardV2.DashboardResourceInfo.TypeMeta().APIVersion,
"kind": "Dashboard",
"metadata": map[string]interface{}{
"generateName": "test-",
@@ -786,12 +787,12 @@ func createTestContext(t *testing.T, helper *apis.K8sTestHelper, orgUsers apis.O
// getDashboardGVR returns the dashboard GroupVersionResource
func getDashboardGVR() schema.GroupVersionResource {
return dashboardv1.DashboardResourceInfo.GroupVersionResource()
return dashboardV1.DashboardResourceInfo.GroupVersionResource()
}
// getFolderGVR returns the folder GroupVersionResource
func getFolderGVR() schema.GroupVersionResource {
return folders.FolderResourceInfo.GroupVersionResource()
return foldersV1.FolderResourceInfo.GroupVersionResource()
}
// Get a resource client for the specified user
@@ -822,8 +823,8 @@ func createFolderObject(t *testing.T, title string, namespace string, parentFold
folderObj := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": folders.FolderResourceInfo.GroupVersion().String(),
"kind": folders.FolderResourceInfo.GroupVersionKind().Kind,
"apiVersion": foldersV1.FolderResourceInfo.GroupVersion().String(),
"kind": foldersV1.FolderResourceInfo.GroupVersionKind().Kind,
"metadata": map[string]interface{}{
"generateName": "test-folder-",
"namespace": namespace,
@@ -878,8 +879,8 @@ func createDashboardObject(t *testing.T, title string, folderUID string, generat
dashObj := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": dashboardv1.DashboardResourceInfo.GroupVersion().String(),
"kind": dashboardv1.DashboardResourceInfo.GroupVersionKind().Kind,
"apiVersion": dashboardV1.DashboardResourceInfo.GroupVersion().String(),
"kind": dashboardV1.DashboardResourceInfo.GroupVersionKind().Kind,
"metadata": map[string]interface{}{
"generateName": "test-",
"annotations": map[string]interface{}{
@@ -1464,7 +1465,7 @@ func runDashboardPermissionTests(t *testing.T, ctx TestContext) {
//statusErr := ctx.Helper.AsStatusError(err)
//require.Equal(t, http.StatusNotFound, int(statusErr.Status().Code), "Should get 404 Not Found")
// TODO: Find out why this throws a 500 instead of a 404 with this message:
// an error on the server (\"Internal Server Error: \\\"/apis/dashboard.grafana.app/v1alpha1/namespaces/org-3/dashboards/test-cs6xk\\\": Dashboard not found\") has prevented the request from succeeding"
// an error on the server (\"Internal Server Error: \\\"/apis/dashboard.grafana.app/v1beta1/namespaces/org-3/dashboards/test-cs6xk\\\": Dashboard not found\") has prevented the request from succeeding"
// Clean up
err = adminClient.Resource.Delete(context.Background(), org1DashUID, v1.DeleteOptions{})
@@ -1649,7 +1650,7 @@ func runCrossOrgTests(t *testing.T, org1Ctx, org2Ctx TestContext) {
require.Error(t, err, "Should not be able to access dashboard from another org")
//statusErr := org1Ctx.Helper.AsStatusError(err)
// TODO: Find out why this throws a 500 instead of a 404 with this message:
// "an error on the server (\"Internal Server Error: \\\"/apis/dashboard.grafana.app/v1alpha1/namespaces/default/dashboards/test-rbm2q\\\": Dashboard not found\") has prevented the request from succeeding"
// "an error on the server (\"Internal Server Error: \\\"/apis/dashboard.grafana.app/v1beta1/namespaces/default/dashboards/test-rbm2q\\\": Dashboard not found\") has prevented the request from succeeding"
//require.Equal(t, http.StatusNotFound, int(statusErr.Status().Code), "Should get 404 Not Found")
// Get a dashboard as admin from the target org to then send an update request
@@ -1871,7 +1872,7 @@ func runDashboardHttpTest(t *testing.T, ctx TestContext, foreignOrgCtx TestConte
"POST", locTC.name, userTC.name)
// Construct the dashboard URL
dashboardPath := fmt.Sprintf("/apis/dashboard.grafana.app/v1alpha1/namespaces/%s/dashboards", ctx.Helper.Namespacer(ctx.OrgID))
dashboardPath := fmt.Sprintf("/apis/dashboard.grafana.app/v1beta1/namespaces/%s/dashboards", ctx.Helper.Namespacer(ctx.OrgID))
// Create dashboard JSON with a single template
var metadata string
@@ -1884,7 +1885,7 @@ func runDashboardHttpTest(t *testing.T, ctx TestContext, foreignOrgCtx TestConte
dashboardJSON := fmt.Sprintf(`{
"kind": "Dashboard",
"apiVersion": "dashboard.grafana.app/v1alpha1",
"apiVersion": "dashboard.grafana.app/v1beta1",
"metadata": {
%s
},
@@ -1915,7 +1916,7 @@ func runDashboardHttpTest(t *testing.T, ctx TestContext, foreignOrgCtx TestConte
"Failed to %s dashboard as %s: %s", "POST", userTC.user.Identity.GetLogin(), createResp.Response.Status)
// Construct the dashboard path with the actual UID for GET/DELETE
dashboardPath = fmt.Sprintf("/apis/dashboard.grafana.app/v1alpha1/namespaces/%s/dashboards/%s",
dashboardPath = fmt.Sprintf("/apis/dashboard.grafana.app/v1beta1/namespaces/%s/dashboards/%s",
ctx.Helper.Namespacer(ctx.OrgID), dashboardUID)
// Verify the dashboard was created by getting it via the admin client
+1 -1
View File
@@ -1,4 +1,4 @@
apiVersion: dashboard.grafana.app/v1alpha1
apiVersion: dashboard.grafana.app/v1beta1
kind: Dashboard
metadata:
name: test-v1