update notification manager to v2.0 (#5030)

Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>
This commit is contained in:
wanjunlei
2022-07-05 16:04:33 +08:00
committed by GitHub
parent 8e00ba29ca
commit 5cead172cd
87 changed files with 7877 additions and 253 deletions

View File

@@ -21,20 +21,38 @@ package v2beta2
import (
"net/http"
nm "kubesphere.io/kubesphere/pkg/simple/client/notification"
"github.com/emicklei/go-restful"
openapi "github.com/emicklei/go-restful-openapi"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/query"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
kubesphere "kubesphere.io/kubesphere/pkg/client/clientset/versioned"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/server/errors"
"kubesphere.io/kubesphere/pkg/simple/client/notification"
)
var GroupVersion = schema.GroupVersion{Group: "notification.kubesphere.io", Version: "v2beta2"}
const (
GroupName = "notification.kubesphere.io"
KeyOpenAPITags = openapi.KeyOpenAPITags
)
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v2beta2"}
func AddToContainer(
container *restful.Container,
informers informers.InformerFactory,
k8sClient kubernetes.Interface,
ksClient kubesphere.Interface,
options *notification.Options) error {
func AddToContainer(container *restful.Container, option *nm.Options) error {
h := newHandler(option)
ws := runtime.NewWebService(GroupVersion)
h := newNotificationHandler(informers, k8sClient, ksClient, options)
ws.Route(ws.POST("/configs/notification/verification").
Reads("").
To(h.Verify).
@@ -45,6 +63,106 @@ func AddToContainer(container *restful.Container, option *nm.Options) error {
Param(ws.PathParameter("user", "user name")).
Returns(http.StatusOK, api.StatusOK, http.Response{}.Body)).
Doc("Provide validation for notification-manager information")
// apis for global notification config, receiver, and secret
ws.Route(ws.GET("/{resources}").
To(h.ListResource).
Doc("list the notification configs or receivers").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, routers, silences")).
Param(ws.QueryParameter(query.ParameterName, "name used for filtering").Required(false)).
Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector used for filtering").Required(false)).
Param(ws.QueryParameter("type", "config or receiver type, known values include dingtalk, email, feishu, slack, webhook, wechat").Required(false)).
Param(ws.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")).
Param(ws.QueryParameter(query.ParameterLimit, "limit").Required(false)).
Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")).
Param(ws.QueryParameter(query.ParameterOrderBy, "sort parameters, e.g. orderBy=createTime")).
Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}))
ws.Route(ws.GET("/{resources}/{name}").
To(h.GetResource).
Doc("get the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, routers, silences")).
Param(ws.PathParameter(query.ParameterName, "the name of the resource")).
Param(ws.QueryParameter("type", "config or receiver type, known values include dingtalk, feishu, email, slack, webhook, wechat").Required(false)).
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.POST("/{resources}").
To(h.CreateResource).
Doc("create a notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, routers, silences")).
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.PUT("/{resources}/{name}").
To(h.UpdateResource).
Doc("update the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, routers, silences")).
Param(ws.PathParameter(query.ParameterName, "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.DELETE("/{resources}/{name}").
To(h.DeleteResource).
Doc("delete the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, routers, silences")).
Param(ws.PathParameter(query.ParameterName, "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, errors.None))
// apis for tenant notification config and receiver
ws.Route(ws.GET("/users/{user}/{resources}").
To(h.ListResource).
Doc("list the notification configs or receivers").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("user", "user name")).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, silences")).
Param(ws.QueryParameter(query.ParameterName, "name used for filtering").Required(false)).
Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector used for filtering").Required(false)).
Param(ws.QueryParameter("type", "config or receiver type, known values include dingtalk, email, feishu, slack, webhook, wechat").Required(false)).
Param(ws.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")).
Param(ws.QueryParameter(query.ParameterLimit, "limit").Required(false)).
Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")).
Param(ws.QueryParameter(query.ParameterOrderBy, "sort parameters, e.g. orderBy=createTime")).
Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}))
ws.Route(ws.GET("/users/{user}/{resources}/{name}").
To(h.GetResource).
Doc("get the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("user", "user name")).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, silences")).
Param(ws.PathParameter(query.ParameterName, "the name of the resource")).
Param(ws.QueryParameter("type", "config or receiver type, known values include dingtalk, email, feishu, slack, webhook, wechat").Required(false)).
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.POST("/users/{user}/{resources}").
To(h.CreateResource).
Doc("create the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("user", "user name")).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, silences")).
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.PUT("/users/{user}/{resources}/{name}").
To(h.UpdateResource).
Doc("update the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("user", "user name")).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, silences")).
Param(ws.PathParameter(query.ParameterName, "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.DELETE("/users/{user}/{resources}/{name}").
To(h.DeleteResource).
Doc("delete the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("user", "user name")).
Param(ws.PathParameter("resources", "known values include configs, receivers, secrets, silences")).
Param(ws.PathParameter(query.ParameterName, "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, errors.None))
container.Add(ws)
return nil
}