add request err with api not enabled to alerting
Signed-off-by: junotx <junotx@126.com>
This commit is contained in:
@@ -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")
|
||||
ErrAlertingRuleNotFound = errors.New("The alerting rule was not found")
|
||||
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_]*`)
|
||||
)
|
||||
|
||||
@@ -41,10 +41,24 @@ func AddToContainer(container *restful.Container, informers informers.InformerFa
|
||||
promResourceClient promresourcesclient.Interface, ruleClient alerting.RuleClient,
|
||||
option *alerting.Options) error {
|
||||
|
||||
handler := newHandler(informers, promResourceClient, ruleClient, option)
|
||||
|
||||
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").
|
||||
To(handler.handleListCustomAlertingRules).
|
||||
Doc("list the cluster-level custom alerting rules").
|
||||
|
||||
Reference in New Issue
Block a user