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 2022/08/11 02:56:24 UTC
[apisix] branch master updated: feat(deployment): disable request proxy in control plane (#7629)
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 c07fe696f feat(deployment): disable request proxy in control plane (#7629)
c07fe696f is described below
commit c07fe696f97fe1ca944cb1764f0981a572a5e76f
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Thu Aug 11 10:56:17 2022 +0800
feat(deployment): disable request proxy in control plane (#7629)
---
apisix/cli/ngx_tpl.lua | 45 +++++++++++++++++-----------------
apisix/cli/ops.lua | 9 ++++++-
t/cli/test_deployment_control_plane.sh | 22 ++++++++++++++++-
3 files changed, 52 insertions(+), 24 deletions(-)
diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua
index b459cd027..0f5d84b17 100644
--- a/apisix/cli/ngx_tpl.lua
+++ b/apisix/cli/ngx_tpl.lua
@@ -308,28 +308,6 @@ http {
{% end %}
{% end %}
- {% if enabled_plugins["proxy-cache"] then %}
- # for proxy cache
- {% for _, cache in ipairs(proxy_cache.zones) do %}
- {% if cache.disk_path and cache.cache_levels and cache.disk_size then %}
- proxy_cache_path {* cache.disk_path *} levels={* cache.cache_levels *} keys_zone={* cache.name *}:{* cache.memory_size *} inactive=1d max_size={* cache.disk_size *} use_temp_path=off;
- {% else %}
- lua_shared_dict {* cache.name *} {* cache.memory_size *};
- {% end %}
- {% end %}
- {% end %}
-
- {% if enabled_plugins["proxy-cache"] then %}
- # for proxy cache
- map $upstream_cache_zone $upstream_cache_zone_info {
- {% for _, cache in ipairs(proxy_cache.zones) do %}
- {% if cache.disk_path and cache.cache_levels and cache.disk_size then %}
- {* cache.name *} {* cache.disk_path *},{* cache.cache_levels *};
- {% end %}
- {% end %}
- }
- {% end %}
-
{% if enabled_plugins["error-log-logger"] then %}
lua_capture_error_log 10m;
{% end %}
@@ -584,6 +562,27 @@ http {
{* conf_server *}
{% end %}
+ {% if deployment_role ~= "control_plane" then %}
+
+ {% if enabled_plugins["proxy-cache"] then %}
+ # for proxy cache
+ {% for _, cache in ipairs(proxy_cache.zones) do %}
+ {% if cache.disk_path and cache.cache_levels and cache.disk_size then %}
+ proxy_cache_path {* cache.disk_path *} levels={* cache.cache_levels *} keys_zone={* cache.name *}:{* cache.memory_size *} inactive=1d max_size={* cache.disk_size *} use_temp_path=off;
+ {% else %}
+ lua_shared_dict {* cache.name *} {* cache.memory_size *};
+ {% end %}
+ {% end %}
+
+ map $upstream_cache_zone $upstream_cache_zone_info {
+ {% for _, cache in ipairs(proxy_cache.zones) do %}
+ {% if cache.disk_path and cache.cache_levels and cache.disk_size then %}
+ {* cache.name *} {* cache.disk_path *},{* cache.cache_levels *};
+ {% end %}
+ {% end %}
+ }
+ {% end %}
+
server {
{% for _, item in ipairs(node_listen) do %}
listen {* item.ip *}:{* item.port *} default_server {% if item.enable_http2 then %} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %};
@@ -856,6 +855,8 @@ http {
}
}
}
+ {% end %}
+
# http end configuration snippet starts
{% if http_end_configuration_snippet then %}
{* http_end_configuration_snippet *}
diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua
index ca091d9c6..2cd72837a 100644
--- a/apisix/cli/ops.lua
+++ b/apisix/cli/ops.lua
@@ -541,7 +541,13 @@ Please modify "admin_key" in conf/config.yaml .
end
if yaml_conf.deployment and yaml_conf.deployment.role then
- env.deployment_role = yaml_conf.deployment.role
+ local role = yaml_conf.deployment.role
+ env.deployment_role = role
+
+ if role == "control_plane" and not admin_server_addr then
+ local listen = node_listen[1]
+ admin_server_addr = str_format("%s:%s", listen.ip, listen.port)
+ end
end
-- Using template.render
@@ -550,6 +556,7 @@ Please modify "admin_key" in conf/config.yaml .
lua_cpath = env.pkg_cpath_org,
os_name = util.trim(util.execute_cmd("uname")),
apisix_lua_home = env.apisix_home,
+ deployment_role = env.deployment_role,
use_apisix_openresty = use_apisix_openresty,
error_log = {level = "warn"},
enable_http = enable_http,
diff --git a/t/cli/test_deployment_control_plane.sh b/t/cli/test_deployment_control_plane.sh
index f104e5e73..99affddb3 100755
--- a/t/cli/test_deployment_control_plane.sh
+++ b/t/cli/test_deployment_control_plane.sh
@@ -98,11 +98,31 @@ make run
sleep 1
code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1')
-make stop
if [ ! $code -eq 200 ]; then
+ make stop
echo "failed: could not work with etcd"
exit 1
fi
echo "passed: work well with etcd in control plane"
+
+curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "upstream": {
+ "nodes": {
+ "httpbin.org:80": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/*"
+}'
+
+code=$(curl -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/c -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1')
+make stop
+if [ ! $code -eq 404 ]; then
+ echo "failed: should disable request proxy"
+ exit 1
+fi
+
+echo "passed: should disable request proxy"