Skip to content

Commit

Permalink
fix: delete route failure (#2074)
Browse files Browse the repository at this point in the history
Signed-off-by: 张启航 <[email protected]>
  • Loading branch information
ZhangSetSail authored Nov 21, 2024
1 parent df94eff commit c2c09a8
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions api/controller/apigateway/api_gateway_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func (g Struct) CreateHTTPAPIRoute(w http.ResponseWriter, r *http.Request) {
}, v1.CreateOptions{})
if err == nil {
name := r.URL.Query().Get("name")
name = name[1:]
if name != "" {
err = c.ApisixRoutes(tenant.Namespace).Delete(r.Context(), name, v1.DeleteOptions{})
if err != nil {
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:]
c := k8s.Default().ApiSixClient.ApisixV2()

err := c.ApisixRoutes(tenant.Namespace).Delete(r.Context(), name, v1.DeleteOptions{})
Expand All @@ -311,24 +312,6 @@ func (g Struct) DeleteHTTPAPIRoute(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, deleteName)
return
}
if errors.IsNotFound(err) {
list, _ := c.ApisixRoutes(tenant.Namespace).List(r.Context(), v1.ListOptions{
LabelSelector: "host=" + name,
})

for _, item := range list.Items {
err = c.ApisixRoutes(tenant.Namespace).Delete(r.Context(), item.Spec.HTTP[0].Name, v1.DeleteOptions{})
if err != nil {
logrus.Errorf("delete route %v failure: %v", item.Name, err)
httputil.ReturnBcodeError(r, w, bcode.ErrRouteDelete)
return
}
deleteName = append(deleteName, item.Spec.HTTP[0].Name)

}
httputil.ReturnSuccess(r, w, deleteName)
return
}
logrus.Errorf("delete route error %s", err.Error())
httputil.ReturnBcodeError(r, w, bcode.ErrRouteDelete)
}
Expand Down

0 comments on commit c2c09a8

Please sign in to comment.