You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/07/02 02:58:05 UTC
[apisix] branch master updated: feat(cli): check if control port
conflicts with the node port (#4504)
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 2832a69 feat(cli): check if control port conflicts with the node port (#4504)
2832a69 is described below
commit 2832a69af599433c0646b75d27d6a4e8d62e352b
Author: Mao18 <ha...@gmail.com>
AuthorDate: Fri Jul 2 10:57:57 2021 +0800
feat(cli): check if control port conflicts with the node port (#4504)
Co-authored-by: zhangya <zh...@cvte.com>
---
apisix/cli/ops.lua | 57 ++++++++++++++++++++++++++++++++++-----------------
t/cli/test_control.sh | 14 +++++++++++++
2 files changed, 52 insertions(+), 19 deletions(-)
diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua
index 300b380..f02b93e 100644
--- a/apisix/cli/ops.lua
+++ b/apisix/cli/ops.lua
@@ -407,16 +407,53 @@ Please modify "admin_key" in conf/config.yaml .
util.die("missing apisix.proxy_cache for plugin proxy-cache\n")
end
+ local control_port
+ local control_server_addr
+ if yaml_conf.apisix.enable_control then
+ if not yaml_conf.apisix.control then
+ control_server_addr = "127.0.0.1:9090"
+ else
+ local ip = yaml_conf.apisix.control.ip
+ local port = tonumber(yaml_conf.apisix.control.port)
+
+ if ip == nil then
+ ip = "127.0.0.1"
+ end
+
+ if not port then
+ port = 9090
+ end
+
+ control_server_addr = ip .. ":" .. port
+ control_port = port
+ end
+ end
+
-- support multiple ports listen, compatible with the original style
if type(yaml_conf.apisix.node_listen) == "number" then
+
+ if yaml_conf.apisix.node_listen == control_port then
+ util.die("control port conflicts with node_listen port\n")
+ end
+
local node_listen = {{port = yaml_conf.apisix.node_listen}}
yaml_conf.apisix.node_listen = node_listen
elseif type(yaml_conf.apisix.node_listen) == "table" then
local node_listen = {}
for index, value in ipairs(yaml_conf.apisix.node_listen) do
if type(value) == "number" then
+
+ if value == control_port then
+ util.die("control port conflicts with node_listen port\n")
+ end
+
table_insert(node_listen, index, {port = value})
elseif type(value) == "table" then
+
+ if type(value.port) == "number" and value.port == control_port then
+ util.die("control port conflicts with node_listen port\n")
+ end
+
table_insert(node_listen, index, value)
end
end
@@ -500,6 +537,7 @@ Please modify "admin_key" in conf/config.yaml .
enabled_plugins = enabled_plugins,
dubbo_upstream_multiplex_count = dubbo_upstream_multiplex_count,
tcp_enable_ssl = tcp_enable_ssl,
+ control_server_addr = control_server_addr,
}
if not yaml_conf.apisix then
@@ -523,25 +561,6 @@ Please modify "admin_key" in conf/config.yaml .
sys_conf[k] = v
end
- if yaml_conf.apisix.enable_control then
- if not yaml_conf.apisix.control then
- sys_conf.control_server_addr = "127.0.0.1:9090"
- else
- local ip = yaml_conf.apisix.control.ip
- local port = tonumber(yaml_conf.apisix.control.port)
-
- if ip == nil then
- ip = "127.0.0.1"
- end
-
- if not port then
- port = 9090
- end
-
- sys_conf.control_server_addr = ip .. ":" .. port
- end
- end
-
if yaml_conf.plugin_attr.prometheus then
local prometheus = yaml_conf.plugin_attr.prometheus
if prometheus.enable_export_server then
diff --git a/t/cli/test_control.sh b/t/cli/test_control.sh
index d6c50bf..ab12c45 100755
--- a/t/cli/test_control.sh
+++ b/t/cli/test_control.sh
@@ -115,4 +115,18 @@ if grep "listen 127.0.0.1:9090;" conf/nginx.conf > /dev/null; then
exit 1
fi
+echo '
+apisix:
+ node_listen: 9090
+ enable_control: true
+ control:
+ port: 9090
+' > conf/config.yaml
+
+out=$(make init 2>&1 || true)
+if ! echo "$out" | grep "control port conflicts with node_listen port"; then
+ echo "failed: can't detect port conflicts"
+ exit 1
+fi
+
echo "pass: access control server"