提交 3a0e0891 编写于 作者: J junotx

add request err with api not enabled to alerting

Signed-off-by: Njunotx <junotx@126.com>
上级 5467b2a1
...@@ -39,6 +39,7 @@ var ( ...@@ -39,6 +39,7 @@ var (
ErrThanosRulerNotEnabled = errors.New("The request operation to custom alerting rule could not be done because thanos ruler is not enabled") ErrThanosRulerNotEnabled = errors.New("The request operation to custom alerting rule could not be done because thanos ruler is not enabled")
ErrAlertingRuleNotFound = errors.New("The alerting rule was not found") ErrAlertingRuleNotFound = errors.New("The alerting rule was not found")
ErrAlertingRuleAlreadyExists = errors.New("The alerting rule already exists") ErrAlertingRuleAlreadyExists = errors.New("The alerting rule already exists")
ErrAlertingAPIV2NotEnabled = errors.New("The alerting v2 API was not enabled")
ruleLabelNameMatcher = regexp.MustCompile(`[a-zA-Z_][a-zA-Z0-9_]*`) ruleLabelNameMatcher = regexp.MustCompile(`[a-zA-Z_][a-zA-Z0-9_]*`)
) )
......
...@@ -41,10 +41,24 @@ func AddToContainer(container *restful.Container, informers informers.InformerFa ...@@ -41,10 +41,24 @@ func AddToContainer(container *restful.Container, informers informers.InformerFa
promResourceClient promresourcesclient.Interface, ruleClient alerting.RuleClient, promResourceClient promresourcesclient.Interface, ruleClient alerting.RuleClient,
option *alerting.Options) error { option *alerting.Options) error {
handler := newHandler(informers, promResourceClient, ruleClient, option)
ws := runtime.NewWebService(GroupVersion) ws := runtime.NewWebService(GroupVersion)
if informers == nil || promResourceClient == nil || ruleClient == nil || option == nil {
h := func(req *restful.Request, resp *restful.Response) {
ksapi.HandleBadRequest(resp, nil, alertingv2alpha1.ErrAlertingAPIV2NotEnabled)
return
}
ws.Route(ws.GET("/{path:*}").To(h).Returns(http.StatusOK, ksapi.StatusOK, nil))
ws.Route(ws.PUT("/{path:*}").To(h).Returns(http.StatusOK, ksapi.StatusOK, nil))
ws.Route(ws.POST("/{path:*}").To(h).Returns(http.StatusOK, ksapi.StatusOK, nil))
ws.Route(ws.DELETE("/{path:*}").To(h).Returns(http.StatusOK, ksapi.StatusOK, nil))
ws.Route(ws.PATCH("/{path:*}").To(h).Returns(http.StatusOK, ksapi.StatusOK, nil))
container.Add(ws)
return nil
}
handler := newHandler(informers, promResourceClient, ruleClient, option)
ws.Route(ws.GET("/rules"). ws.Route(ws.GET("/rules").
To(handler.handleListCustomAlertingRules). To(handler.handleListCustomAlertingRules).
Doc("list the cluster-level custom alerting rules"). Doc("list the cluster-level custom alerting rules").
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册