tzssangglass commented on code in PR #8219:
URL: https://github.com/apache/apisix/pull/8219#discussion_r1022219080
##########
apisix/admin/stream_routes.lua:
##########
@@ -16,15 +16,38 @@
--
local core = require("apisix.core")
local utils = require("apisix.admin.utils")
+local iterate_values = require("apisix.core.config_util").iterate_values
local stream_route_checker =
require("apisix.stream.router.ip_port").stream_route_checker
local tostring = tostring
+local table = table
+local tonumber = tonumber
local _M = {
version = 0.1,
need_v3_filter = true,
}
+local function check_router_refer(items, id)
+ local warn_message = nil
+ local refer_list = core.tablepool.fetch("refer_list",#items,0)
Review Comment:
```suggestion
local refer_list = core.tablepool.fetch("refer_list", #items, 0)
```
##########
apisix/admin/stream_routes.lua:
##########
@@ -16,15 +16,38 @@
--
local core = require("apisix.core")
local utils = require("apisix.admin.utils")
+local iterate_values = require("apisix.core.config_util").iterate_values
local stream_route_checker =
require("apisix.stream.router.ip_port").stream_route_checker
local tostring = tostring
+local table = table
+local tonumber = tonumber
local _M = {
version = 0.1,
need_v3_filter = true,
}
+local function check_router_refer(items, id)
+ local warn_message = nil
+ local refer_list = core.tablepool.fetch("refer_list",#items,0)
+ for _, item in iterate_values(items) do
+ if item.value == nil then
+ goto CONTINUE
+ end
+ local route = item.value
+ if route.protocol and route.protocol.superior_id and
route.protocol.superior_id == id then
+ table.insert(refer_list,item["key"])
Review Comment:
```suggestion
table.insert(refer_list, item["key"])
```
##########
apisix/admin/stream_routes.lua:
##########
@@ -16,15 +16,38 @@
--
local core = require("apisix.core")
local utils = require("apisix.admin.utils")
+local iterate_values = require("apisix.core.config_util").iterate_values
local stream_route_checker =
require("apisix.stream.router.ip_port").stream_route_checker
local tostring = tostring
+local table = table
+local tonumber = tonumber
local _M = {
version = 0.1,
need_v3_filter = true,
}
+local function check_router_refer(items, id)
+ local warn_message = nil
+ local refer_list = core.tablepool.fetch("refer_list",#items,0)
+ for _, item in iterate_values(items) do
+ if item.value == nil then
+ goto CONTINUE
+ end
+ local route = item.value
+ if route.protocol and route.protocol.superior_id and
route.protocol.superior_id == id then
+ table.insert(refer_list,item["key"])
+ end
+ ::CONTINUE::
+ end
+ if #refer_list > 0 then
+ warn_message = "/stream_routes/" .. id .. " is referred by "
+ .. table.concat(refer_list,";;")
+ end
+ core.tablepool.release("refer_list",refer_list)
Review Comment:
```suggestion
core.tablepool.release("refer_list", refer_list)
```
##########
apisix/admin/stream_routes.lua:
##########
@@ -142,6 +165,15 @@ function _M.delete(id)
return 400, {error_msg = "missing stream route id"}
end
+ local status, body = _M.get()
+ local items = body.list
+ if tonumber(status) == 200 and #items > 1 then
+ local warn_message = check_router_refer(items,id)
Review Comment:
```suggestion
local warn_message = check_router_refer(items, id)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]