Skip to content

Commit

Permalink
fix: fix the problem of unable to delete routes (#2096)
Browse files Browse the repository at this point in the history
Signed-off-by: 张启航 <[email protected]>
  • Loading branch information
ZhangSetSail authored Dec 16, 2024
1 parent f61c7f1 commit 531c350
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/controller/apigateway/api_gateway_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apigateway
import (
"fmt"
"net/http"
"regexp"
"strings"

v2 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2"
Expand Down Expand Up @@ -248,7 +249,7 @@ func (g Struct) CreateHTTPAPIRoute(w http.ResponseWriter, r *http.Request) {
if err == nil {
name := r.URL.Query().Get("name")
if name != "" {
name = name[1:]
name = removeLeadingDigits(name)
err = c.ApisixRoutes(tenant.Namespace).Delete(r.Context(), name, v1.DeleteOptions{})
if err != nil {
logrus.Errorf("delete route %v failure: %v", name, err)
Expand Down Expand Up @@ -302,7 +303,7 @@ func (g Struct) DeleteHTTPAPIRoute(w http.ResponseWriter, r *http.Request) {
var deleteName = make([]string, 0)
tenant := r.Context().Value(ctxutil.ContextKey("tenant")).(*dbmodel.Tenants)
name := chi.URLParam(r, "name")
name = name[1:]
name = removeLeadingDigits(name)
c := k8s.Default().ApiSixClient.ApisixV2()

err := c.ApisixRoutes(tenant.Namespace).Delete(r.Context(), name, v1.DeleteOptions{})
Expand Down Expand Up @@ -515,3 +516,10 @@ func (g Struct) DeleteTCPRoute(w http.ResponseWriter, r *http.Request) {
}
httputil.ReturnSuccess(r, w, name)
}

func removeLeadingDigits(name string) string {
// 使用正则表达式匹配前面的数字
re := regexp.MustCompile(`^\d+`)
// 将匹配到的数字替换为空字符串
return re.ReplaceAllString(name, "")
}

0 comments on commit 531c350

Please sign in to comment.