tao12345666333 opened a new issue #5917: URL: https://github.com/apache/apisix/issues/5917
### Issue description When a `PluginConfig` is referenced by multiple `Routes`, it can still be deleted. I expect APISIX can handle it the same as `Upstream`. If an `Upstream` is referenced by multiple `Routes`, an error will be reported when deleting. ### Environment - apisix version (cmd: `apisix version`): 2.10.2 - OS (cmd: `uname -a`): - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`): - etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API): - apisix-dashboard version, if have: - the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner): - luarocks version, if the issue is about installation (cmd: `luarocks --version`): ### Steps to reproduce * create PluginConfig ```bash bash-5.1# curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' { "desc": "吾乃插件配置1", "plugins": { "limit-count": { "count": 2, "time_window": 60, "rejected_code": 503 } } }' HTTP/1.1 201 Created Date: Fri, 24 Dec 2021 08:16:42 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive Server: APISIX/2.10.2 Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Access-Control-Expose-Headers: * Access-Control-Max-Age: 3600 {"node":{"value":{"desc":"吾乃插件配置1","create_time":1640333802,"id":"1","update_time":1640333802,"plugins":{"limit-count":{"time_window":60,"key_type":"var","rejected_code":503,"policy":"local","allo w_degradation":false,"show_limit_quota_header":true,"key":"remote_addr","count":2}}},"key":"\/apisix\/plugin_configs\/1"},"action":"set"} * create Route 1 ```bash bash-5.1# curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' { "uris": ["/index.html"], "plugin_config_id": 1, "upstream": { "type": "roundrobin", "nodes": { "39.97.63.215:80": 1 } } }' HTTP/1.1 201 Created Date: Fri, 24 Dec 2021 08:17:22 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive Server: APISIX/2.10.2 Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Access-Control-Expose-Headers: * Access-Control-Max-Age: 3600 {"node":{"value":{"plugin_config_id":1,"priority":0,"uris":["\/index.html"],"update_time":1640333842,"create_time":1640333842,"id":"1","status":1,"upstream":{"nodes":{"39.97.63.215:80":1},"scheme":"http ","type":"roundrobin","pass_host":"pass","hash_on":"vars"}},"key":"\/apisix\/routes\/1"},"action":"set"} ``` * create Route 2 ```bash bash-5.1# curl http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' { "uris": ["/index.html"], "plugin_config_id": 1, "upstream": { "type": "roundrobin", "nodes": { "39.97.63.215:80": 1 } } }' HTTP/1.1 201 Created Date: Fri, 24 Dec 2021 08:17:40 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive Server: APISIX/2.10.2 Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Access-Control-Expose-Headers: * Access-Control-Max-Age: 3600 {"node":{"value":{"plugin_config_id":1,"priority":0,"uris":["\/index.html"],"update_time":1640333860,"create_time":1640333860,"id":"2","status":1,"upstream":{"nodes":{"39.97.63.215:80":1},"scheme":"http ","type":"roundrobin","pass_host":"pass","hash_on":"vars"}},"key":"\/apisix\/routes\/2"},"action":"set"} ``` * delete one route, then delete PluginConfig ```bash bash-5.1# curl -X DELETE http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' {"node":{},"key":"\/apisix\/routes\/1","action":"delete","deleted":"1"} bash-5.1# curl http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' {"action":"get","count":1,"node":{"nodes":[{"value":{"plugin_config_id":1,"priority":0,"uris":["\/index.html"],"upstream":{"nodes":{"39.97.63.215:80":1},"scheme":"http","type":"roundrobin","pass_host":" pass","hash_on":"vars"},"status":1,"id":"2","create_time":1640333860,"update_time":1640333860},"createdIndex":15,"modifiedIndex":15,"key":"\/apisix\/routes\/2"}],"dir":true,"key":"\/apisix\/routes"}} bash-5.1# curl -X DELETE http://127.0.0.1:9180/apisix/admin/plugin_configs/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' {"node":{},"key":"\/apisix\/plugin_configs\/1","action":"delete","deleted":"1"} bash-5.1# curl http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' {"action":"get","count":1,"node":{"nodes":[{"value":{"plugin_config_id":1,"priority":0,"uris":["\/index.html"],"upstream":{"nodes":{"39.97.63.215:80":1},"scheme":"http","type":"roundrobin","pass_host":" pass","hash_on":"vars"},"status":1,"id":"2","create_time":1640333860,"update_time":1640333860},"createdIndex":15,"modifiedIndex":15,"key":"\/apisix\/routes\/2"}],"dir":true,"key":"\/apisix\/routes"}} bash-5.1# curl http://127.0.0.1:9180/apisix/admin/plugin_configs -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' {"action":"get","count":0,"node":{"nodes":{},"dir":true,"key":"\/apisix\/plugin_configs"}} ``` ### Actual result Successfully deleted PluginConfig. ### Error log . ### Expected result I hope APISIX can check that it is being referenced and prevent the delete operation. like Upstream. ```bash bash-5.1# curl -X DELETE http://127.0.0.1:9180/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' {"error_msg":"can not delete this upstream, route [5] is still using it now"} ``` -- 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]
