Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the problem of unable to delete routes #2096

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, "")
}
Loading