From 5f886e97b7ccc0759df5160e17717d19c6cf0efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=AF=E8=88=AA?= <101104760+ZhangSetSail@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:56:22 +0800 Subject: [PATCH] fix: delete outer tcp port svc failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张启航 <101104760+ZhangSetSail@users.noreply.github.com> --- .../apigateway/api_gateway_route.go | 41 +++---------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/api/controller/apigateway/api_gateway_route.go b/api/controller/apigateway/api_gateway_route.go index e769e81ea..ebbbe1def 100644 --- a/api/controller/apigateway/api_gateway_route.go +++ b/api/controller/apigateway/api_gateway_route.go @@ -504,46 +504,17 @@ func (g Struct) DeleteTCPRoute(w http.ResponseWriter, r *http.Request) { tenant := r.Context().Value(ctxutil.ContextKey("tenant")).(*dbmodel.Tenants) name := chi.URLParam(r, "name") - // Split name by "-" to get alias and port - parts := strings.Split(name, "-") - if len(parts) != 2 { - httputil.ReturnBcodeError(r, w, bcode.ErrRouteDelete) - return - } - serviceAlias := parts[0] - port := parts[1] - - // Create label selector - labelSelector := fmt.Sprintf("outer=true,port=%s,service_alias=%s", port, serviceAlias) - k := k8s.Default().Clientset.CoreV1() - // List services with the specified labels - logrus.Infof("show tenant namespace %v and labelSelector %v", tenant.Namespace, labelSelector) - services, err := k.Services(tenant.Namespace).List(r.Context(), v1.ListOptions{ - LabelSelector: labelSelector, - }) + err := k.Services(tenant.Namespace).Delete(r.Context(), name, v1.DeleteOptions{}) if err != nil { - logrus.Errorf("list services error %s", err.Error()) - httputil.ReturnBcodeError(r, w, bcode.ErrRouteDelete) - return - } - logrus.Infof("show service len %v", len(services.Items)) - if len(services.Items) == 0 { - // No services found with these labels - httputil.ReturnSuccess(r, w, name) - return - } - - // Delete all matching services - for _, svc := range services.Items { - err := k.Services(tenant.Namespace).Delete(r.Context(), svc.Name, v1.DeleteOptions{}) - if err != nil && !errors.IsNotFound(err) { - logrus.Errorf("delete service %s error %s", svc.Name, err.Error()) + if errors.IsNotFound(err) { + httputil.ReturnSuccess(r, w, name) + } else { + logrus.Errorf("delete route error %s", err.Error()) httputil.ReturnBcodeError(r, w, bcode.ErrRouteDelete) - return } + return } - httputil.ReturnSuccess(r, w, name) }