K8s: Add dashboard service (requires dev mode) (#78565)

This commit is contained in:
Ryan McKinley
2024-01-10 15:20:30 -08:00
committed by GitHub
parent be12d3919f
commit 2c09f969f1
27 changed files with 4965 additions and 131 deletions

View File

@@ -0,0 +1,114 @@
package dashboards
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/tests/apis"
"github.com/grafana/grafana/pkg/tests/testinfra"
)
func TestRequiresDevMode(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
AppModeProduction: true, // should fail
DisableAnonymous: true,
EnableFeatureToggles: []string{
featuremgmt.FlagGrafanaAPIServer,
featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service
},
})
_, err := helper.NewDiscoveryClient().ServerResourcesForGroupVersion("dashboard.grafana.app/v0alpha1")
require.Error(t, err)
}
func TestDashboardsApp(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
AppModeProduction: false, // required for experimental APIs
DisableAnonymous: true,
EnableFeatureToggles: []string{
featuremgmt.FlagGrafanaAPIServer,
featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service
},
})
_, err := helper.NewDiscoveryClient().ServerResourcesForGroupVersion("dashboard.grafana.app/v0alpha1")
require.NoError(t, err)
t.Run("Check discovery client", func(t *testing.T) {
disco := helper.GetGroupVersionInfoJSON("dashboard.grafana.app")
// fmt.Printf("%s", string(disco))
require.JSONEq(t, `[
{
"freshness": "Current",
"resources": [
{
"resource": "dashboards",
"responseKind": {
"group": "",
"kind": "Dashboard",
"version": ""
},
"scope": "Namespaced",
"singularResource": "dashboard",
"subresources": [
{
"responseKind": {
"group": "",
"kind": "DashboardAccessInfo",
"version": ""
},
"subresource": "access",
"verbs": [
"get"
]
},
{
"responseKind": {
"group": "",
"kind": "DashboardVersionsInfo",
"version": ""
},
"subresource": "versions",
"verbs": [
"get"
]
}
],
"verbs": [
"create",
"delete",
"get",
"list",
"patch",
"update"
]
},
{
"resource": "summary",
"responseKind": {
"group": "",
"kind": "DashboardSummary",
"version": ""
},
"scope": "Namespaced",
"singularResource": "summary",
"verbs": [
"get",
"list"
]
}
],
"version": "v0alpha1"
}
]`, disco)
})
}

View File

@@ -0,0 +1,6 @@
apiVersion: dashboard.grafana.app/v0alpha1
kind: Dashboard
metadata:
generateName: x # anything is ok here... except yes or true -- they become boolean!
spec:
title: Dashboard with auto generated UID ${NOW}

View File

@@ -0,0 +1,6 @@
apiVersion: dashboard.grafana.app/v0alpha1
kind: Dashboard
metadata:
name: test
spec:
title: Test dashboard (apply from k8s; PATCH) X

View File

@@ -0,0 +1,6 @@
apiVersion: dashboard.grafana.app/v0alpha1
kind: Dashboard
metadata:
name: test
spec:
title: Test dashboard (created from k8s; POST)

View File

@@ -0,0 +1,6 @@
apiVersion: dashboard.grafana.app/v0alpha1
kind: Dashboard
metadata:
name: test
spec:
title: Test dashboard (replaced from k8s; PUT)