convert grafana templates to workspace level

Signed-off-by: zhu733756 <zhu733756@kubesphere.io>
This commit is contained in:
zhu733756
2022-01-05 10:35:42 +08:00
parent c6672b7885
commit 600a3de051
9 changed files with 110 additions and 56 deletions

View File

@@ -36,6 +36,8 @@ import (
"kubesphere.io/kubesphere/pkg/informers"
model "kubesphere.io/kubesphere/pkg/models/monitoring"
"kubesphere.io/kubesphere/pkg/simple/client/monitoring"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)
const (
@@ -45,10 +47,10 @@ const (
var GroupVersion = schema.GroupVersion{Group: groupName, Version: "v1alpha3"}
func AddToContainer(c *restful.Container, k8sClient kubernetes.Interface, monitoringClient monitoring.Interface, metricsClient monitoring.Interface, factory informers.InformerFactory, ksClient versioned.Interface, opOptions *openpitrixoptions.Options) error {
func AddToContainer(c *restful.Container, k8sClient kubernetes.Interface, monitoringClient monitoring.Interface, metricsClient monitoring.Interface, factory informers.InformerFactory, ksClient versioned.Interface, opOptions *openpitrixoptions.Options, rtClient runtimeclient.Client) error {
ws := runtime.NewWebService(GroupVersion)
h := NewHandler(k8sClient, monitoringClient, metricsClient, factory, ksClient, nil, nil, opOptions)
h := NewHandler(k8sClient, monitoringClient, metricsClient, factory, ksClient, nil, nil, opOptions, rtClient)
ws.Route(ws.GET("/kubesphere").
To(h.handleKubeSphereMetricsQuery).
@@ -555,6 +557,16 @@ func AddToContainer(c *restful.Container, k8sClient kubernetes.Interface, monito
Returns(http.StatusOK, respOK, monitoringdashboardv1alpha2.ClusterDashboard{})).
Produces(restful.MIME_JSON)
ws.Route(ws.POST("/namespaces/{namespace}/dashboards/{grafanaDashboardName}/template").
To(h.handleGrafanaDashboardImport).
Doc("Convert Grafana templates to KubeSphere dashboards.").
Param(ws.PathParameter("grafanaDashboardName", "The name of the Grafana template to be converted").DataType("string").Required(true)).
Param(ws.PathParameter("namespace", "The name of the project").DataType("string").Required(true)).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DashboardTag}).
Writes(monitoringdashboardv1alpha2.Dashboard{}).
Returns(http.StatusOK, respOK, monitoringdashboardv1alpha2.Dashboard{})).
Produces(restful.MIME_JSON)
c.Add(ws)
return nil
}