This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 30c9028 fix: ignore changes of /apisix/plugins/ (#5558)
30c9028 is described below
commit 30c902895b41327907fb007b1ee5e97e6079b6ba
Author: tzssangglass <[email protected]>
AuthorDate: Fri Nov 19 04:10:21 2021 -0600
fix: ignore changes of /apisix/plugins/ (#5558)
---
apisix/plugin.lua | 16 ++++----
t/cli/test_admin.sh | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 120 insertions(+), 7 deletions(-)
diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index b1b7d66..7864a00 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -275,13 +275,15 @@ function _M.load(config)
stream_plugin_names = {}
local plugins_conf = config.value
-- plugins_conf can be nil when another instance writes into etcd key
"/apisix/plugins/"
- if plugins_conf then
- for _, conf in ipairs(plugins_conf) do
- if conf.stream then
- core.table.insert(stream_plugin_names, conf.name)
- else
- core.table.insert(http_plugin_names, conf.name)
- end
+ if not plugins_conf then
+ return local_plugins
+ end
+
+ for _, conf in ipairs(plugins_conf) do
+ if conf.stream then
+ core.table.insert(stream_plugin_names, conf.name)
+ else
+ core.table.insert(http_plugin_names, conf.name)
end
end
end
diff --git a/t/cli/test_admin.sh b/t/cli/test_admin.sh
index ac691b1..ecfbffc 100755
--- a/t/cli/test_admin.sh
+++ b/t/cli/test_admin.sh
@@ -229,3 +229,114 @@ fi
make stop
echo "pass: sync /apisix/plugins from etcd when disabling admin successfully"
+
+
+
+# ignore changes to /apisix/plugins/ due to init_etcd
+echo '
+apisix:
+ enable_admin: false
+plugins:
+ - node-status
+nginx_config:
+ error_log_level: info
+' > conf/config.yaml
+
+rm logs/error.log
+make init
+make run
+
+# first time check node status api
+code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
http://127.0.0.1:9080/apisix/status)
+if [ ! $code -eq 200 ]; then
+ echo "failed: first time check node status api failed"
+ exit 1
+fi
+
+# mock another instance init etcd dir
+make init
+sleep 1
+
+# second time check node status api
+code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
http://127.0.0.1:9080/apisix/status)
+if [ ! $code -eq 200 ]; then
+ echo "failed: second time check node status api failed"
+ exit 1
+fi
+
+make stop
+
+echo "pass: ignore changes to /apisix/plugins/ due to init_etcd successfully"
+
+
+# accept changes to /apisix/plugins when enable_admin is false
+echo '
+apisix:
+ enable_admin: false
+plugins:
+ - node-status
+stream_plugins:
+' > conf/config.yaml
+
+rm logs/error.log
+make init
+make run
+
+# first time check node status api
+code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
http://127.0.0.1:9080/apisix/status)
+if [ ! $code -eq 200 ]; then
+ echo "failed: first time check node status api failed"
+ exit 1
+fi
+
+sleep 0.5
+
+# check http plugins load list
+if ! grep -E 'new plugins: {"node-status":true}' logs/error.log; then
+ echo "failed: first time load http plugins list failed"
+ exit 1
+fi
+
+# check stream plugins(no plugins under stream, it will be added below)
+if ! grep -E 'failed to read stream plugin list from local file'
logs/error.log; then
+ echo "failed: first time load stream plugins list failed"
+ exit 1
+fi
+
+# mock another instance add /apisix/plugins
+res=$(etcdctl put "/apisix/plugins"
'[{"name":"node-status"},{"name":"example-plugin"},{"stream":true,"name":"mqtt-proxy"}]')
+if [[ $res != "OK" ]]; then
+ echo "failed: failed to set /apisix/plugins to add more plugins"
+ exit 1
+fi
+
+sleep 0.5
+
+# second time check node status api
+code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code}
http://127.0.0.1:9080/apisix/status)
+if [ ! $code -eq 200 ]; then
+ echo "failed: second time check node status api failed"
+ exit 1
+fi
+
+# check http plugins load list
+if ! grep -E 'new plugins: {"node-status":true}' logs/error.log; then
+ echo "failed: second time load http plugins list failed"
+ exit 1
+fi
+
+# check stream plugins load list
+if ! grep -E 'new plugins: {.*example-plugin' logs/error.log; then
+ echo "failed: second time load stream plugins list failed"
+ exit 1
+fi
+
+
+if grep -E 'new plugins: {}' logs/error.log; then
+ echo "failed: second time load plugins list failed"
+ exit 1
+fi
+
+make stop
+
+echo "pass: ccept changes to /apisix/plugins successfully"