Skip to content

Commit

Permalink
fix: filter nil plugin conf triggered by etcd dir init (apache#5204)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzssangglass authored and spacewander committed Oct 21, 2021
1 parent 85777b4 commit 394ae7d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,14 @@ function _M.load(config)
http_plugin_names = {}
stream_plugin_names = {}
local plugins_conf = config.value
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)
-- 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
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions t/cli/test_admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,24 @@ if ! echo "$out" | grep "Admin API can only be used with etcd config_center"; th
fi

echo "passed: Admin API can only be used with etcd config_center"

# disable Admin API and init plugins syncer
echo '
apisix:
enable_admin: false
' > conf/config.yaml

rm logs/error.log
make init
make run

make init

if grep -E "failed to fetch data from etcd" logs/error.log; then
echo "failed: should sync /apisix/plugins from etcd when disabling admin normal"
exit 1
fi

make stop

echo "pass: sync /apisix/plugins from etcd when disabling admin successfully"

0 comments on commit 394ae7d

Please sign in to comment.