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

@@ -40,7 +40,7 @@ func newNotificationHandler(
ksClient kubesphere.Interface) *handler {
return &handler{
operator: notification.NewOperator(informers, k8sClient, ksClient),
operator: notification.NewOperator(informers, k8sClient, ksClient, nil),
}
}
@@ -51,12 +51,12 @@ func (h *handler) ListResource(req *restful.Request, resp *restful.Response) {
subresource := req.QueryParameter("type")
q := query.ParseQueryParameter(req)
if !h.operator.IsKnownResource(resource, subresource) {
if !h.operator.IsKnownResource(resource, notification.V2beta1, subresource) {
api.HandleBadRequest(resp, req, servererr.New("unknown resource type %s/%s", resource, subresource))
return
}
objs, err := h.operator.List(user, resource, subresource, q)
objs, err := h.operator.ListV2beta1(user, resource, subresource, q)
handleResponse(req, resp, objs, err)
}
@@ -67,12 +67,12 @@ func (h *handler) GetResource(req *restful.Request, resp *restful.Response) {
name := req.PathParameter("name")
subresource := req.QueryParameter("type")
if !h.operator.IsKnownResource(resource, subresource) {
if !h.operator.IsKnownResource(resource, notification.V2beta1, subresource) {
api.HandleBadRequest(resp, req, servererr.New("unknown resource type %s/%s", resource, subresource))
return
}
obj, err := h.operator.Get(user, resource, name, subresource)
obj, err := h.operator.GetV2beta1(user, resource, name, subresource)
handleResponse(req, resp, obj, err)
}
@@ -81,18 +81,18 @@ func (h *handler) CreateResource(req *restful.Request, resp *restful.Response) {
user := req.PathParameter("user")
resource := req.PathParameter("resources")
if !h.operator.IsKnownResource(resource, "") {
if !h.operator.IsKnownResource(resource, notification.V2beta1, "") {
api.HandleBadRequest(resp, req, servererr.New("unknown resource type %s", resource))
return
}
obj := h.operator.GetObject(resource)
obj := h.operator.GetObject(resource, notification.V2beta1)
if err := req.ReadEntity(obj); err != nil {
api.HandleBadRequest(resp, req, err)
return
}
created, err := h.operator.Create(user, resource, obj)
created, err := h.operator.CreateV2beta1(user, resource, obj)
handleResponse(req, resp, created, err)
}
@@ -102,18 +102,18 @@ func (h *handler) UpdateResource(req *restful.Request, resp *restful.Response) {
resource := req.PathParameter("resources")
name := req.PathParameter("name")
if !h.operator.IsKnownResource(resource, "") {
if !h.operator.IsKnownResource(resource, notification.V2beta1, "") {
api.HandleBadRequest(resp, req, servererr.New("unknown resource type %s", resource))
return
}
obj := h.operator.GetObject(resource)
obj := h.operator.GetObject(resource, notification.V2beta1)
if err := req.ReadEntity(obj); err != nil {
api.HandleBadRequest(resp, req, err)
return
}
updated, err := h.operator.Update(user, resource, name, obj)
updated, err := h.operator.UpdateV2beta1(user, resource, name, obj)
handleResponse(req, resp, updated, err)
}
@@ -123,12 +123,12 @@ func (h *handler) DeleteResource(req *restful.Request, resp *restful.Response) {
resource := req.PathParameter("resources")
name := req.PathParameter("name")
if !h.operator.IsKnownResource(resource, "") {
if !h.operator.IsKnownResource(resource, notification.V2beta1, "") {
api.HandleBadRequest(resp, req, servererr.New("unknown resource type %s", resource))
return
}
handleResponse(req, resp, servererr.None, h.operator.Delete(user, resource, name))
handleResponse(req, resp, servererr.None, h.operator.DeleteV2beta1(user, resource, name))
}
func handleResponse(req *restful.Request, resp *restful.Response, obj interface{}, err error) {

View File

@@ -53,6 +53,7 @@ func AddToContainer(
// apis for global notification config, receiver, and secret
ws.Route(ws.GET("/{resources}").
Deprecate().
To(h.ListResource).
Doc("list the notification configs or receivers").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
@@ -67,6 +68,7 @@ func AddToContainer(
Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}))
ws.Route(ws.GET("/{resources}/{name}").
Deprecate().
To(h.GetResource).
Doc("get the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
@@ -76,6 +78,7 @@ func AddToContainer(
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.POST("/{resources}").
Deprecate().
To(h.CreateResource).
Doc("create a notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
@@ -83,6 +86,7 @@ func AddToContainer(
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.PUT("/{resources}/{name}").
Deprecate().
To(h.UpdateResource).
Doc("update the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
@@ -91,6 +95,7 @@ func AddToContainer(
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.DELETE("/{resources}/{name}").
Deprecate().
To(h.DeleteResource).
Doc("delete the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
@@ -100,6 +105,7 @@ func AddToContainer(
// apis for tenant notification config and receiver
ws.Route(ws.GET("/users/{user}/{resources}").
Deprecate().
To(h.ListResource).
Doc("list the notification configs or receivers").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
@@ -115,6 +121,7 @@ func AddToContainer(
Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}))
ws.Route(ws.GET("/users/{user}/{resources}/{name}").
Deprecate().
To(h.GetResource).
Doc("get the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
@@ -125,6 +132,7 @@ func AddToContainer(
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.POST("/users/{user}/{resources}").
Deprecate().
To(h.CreateResource).
Doc("create the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
@@ -133,6 +141,7 @@ func AddToContainer(
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.PUT("/users/{user}/{resources}/{name}").
Deprecate().
To(h.UpdateResource).
Doc("update the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
@@ -142,6 +151,7 @@ func AddToContainer(
Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.DELETE("/users/{user}/{resources}/{name}").
Deprecate().
To(h.DeleteResource).
Doc("delete the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).