diff --git a/api/apiRouters/version2/v2Routers.go b/api/apiRouters/version2/v2Routers.go index 2ce0401c6..171ae7b1a 100644 --- a/api/apiRouters/version2/v2Routers.go +++ b/api/apiRouters/version2/v2Routers.go @@ -206,6 +206,7 @@ func (v2 *V2) serviceRouter() chi.Router { r.Delete("/node-label", controller.GetManager().NodeLabel) // label r.Post("/label", controller.GetManager().Label) + r.Delete("/label", controller.GetManager().Label) //插件 r.Mount("/plugin", v2.serviceRelatePluginRouter()) diff --git a/api/controller/resources.go b/api/controller/resources.go index b7326b3aa..d3cddba7d 100644 --- a/api/controller/resources.go +++ b/api/controller/resources.go @@ -929,7 +929,7 @@ func (t *TenantStruct) Label(w http.ResponseWriter, r *http.Request) { } func (t *TenantStruct) AddLabel(w http.ResponseWriter, r *http.Request) { - logrus.Debugf("add http rule.") + logrus.Debugf("add label") var req api_model.LabelStruct ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req, nil) if !ok { @@ -947,7 +947,21 @@ func (t *TenantStruct) AddLabel(w http.ResponseWriter, r *http.Request) { } func (t *TenantStruct) DeleteLabel(w http.ResponseWriter, r *http.Request) { - + logrus.Debugf("delete label") + var req api_model.LabelStruct + ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req, nil) + if !ok { + return + } + reqJSON, _ := json.Marshal(req) + logrus.Debugf("Request is : %s", string(reqJSON)) + + serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string) + if err := handler.GetServiceManager().DeleteLabel(req.LabelKey, serviceID, req.LabelValues); err != nil { + httputil.ReturnError(r, w, 500, fmt.Sprintf("delete node label failure, %v", err)) + return + } + httputil.ReturnSuccess(r, w, nil) } //DeleteNodeLabel DeleteLabel diff --git a/api/handler/service.go b/api/handler/service.go index 4fec27ce4..60935ad8d 100644 --- a/api/handler/service.go +++ b/api/handler/service.go @@ -280,8 +280,9 @@ func (s *ServiceAction) DeleteLabel(kind, serviceID string, amp []string) error switch kind { case "node": return db.GetManager().TenantServiceLabelDao().DELTenantServiceLabelsByLabelvaluesAndServiceID(serviceID, amp) + default: + return db.GetManager().TenantServiceLabelDao().DelTenantServiceLabels(serviceID, kind, amp) } - return nil } //UpdateServiceLabel UpdateLabel diff --git a/db/dao/dao.go b/db/dao/dao.go index 69f7a8199..9f9766f82 100644 --- a/db/dao/dao.go +++ b/db/dao/dao.go @@ -244,6 +244,7 @@ type TenantServiceLabelDao interface { GetTenantServiceAffinityLabel(serviceID string) ([]*model.TenantServiceLable, error) GetTenantServiceTypeLabel(serviceID string) (*model.TenantServiceLable, error) DELTenantServiceLabelsByLabelvaluesAndServiceID(serviceID string, labelValues []string) error + DelTenantServiceLabels(serviceID string, labelKey string, labelValues []string) error } //LocalSchedulerDao 本地调度信息 diff --git a/db/mysql/dao/tenants.go b/db/mysql/dao/tenants.go index 5a80f9f68..ce5dfb414 100644 --- a/db/mysql/dao/tenants.go +++ b/db/mysql/dao/tenants.go @@ -1263,3 +1263,13 @@ func (t *ServiceLabelDaoImpl) DELTenantServiceLabelsByLabelvaluesAndServiceID(se } return nil } + +//DelTenantServiceLabels deletes labels +func (t *ServiceLabelDaoImpl) DelTenantServiceLabels(serviceID string, labelKey string, labelValues []string) error { + var label model.TenantServiceLable + if err := t.DB.Where("service_id=? and label_key=? and label_value in (?)", + serviceID, labelKey, labelValues).Delete(&label).Error; err != nil { + return err + } + return nil +}