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 a01c0e8fa change: Plugins from plugin_config should not override those 
in the route (#7614)
a01c0e8fa is described below

commit a01c0e8fa8e42018d3212b0f943cb5dce37738d9
Author: 罗泽轩 <[email protected]>
AuthorDate: Sun Aug 7 20:05:44 2022 +0800

    change: Plugins from plugin_config should not override those in the route 
(#7614)
    
    Signed-off-by: spacewander <[email protected]>
---
 apisix/plugin_config.lua                           |  4 +-
 docs/en/latest/terminology/plugin-config.md        |  4 +-
 .../zh/latest/architecture-design/plugin-config.md |  4 +-
 t/config-center-yaml/plugin-configs.t              |  2 +-
 t/node/plugin-configs.t                            | 61 ++++++++++++++++++++++
 5 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/apisix/plugin_config.lua b/apisix/plugin_config.lua
index 903ea6ec1..cc5a6ff38 100644
--- a/apisix/plugin_config.lua
+++ b/apisix/plugin_config.lua
@@ -65,7 +65,9 @@ function _M.merge(route_conf, plugin_config)
     route_conf.value.plugins = core.table.clone(route_conf.value.plugins)
 
     for name, value in pairs(plugin_config.value.plugins) do
-        route_conf.value.plugins[name] = value
+        if not route_conf.value.plugins[name] then
+            route_conf.value.plugins[name] = value
+        end
     end
 
     route_conf.update_count = route_conf.update_count + 1
diff --git a/docs/en/latest/terminology/plugin-config.md 
b/docs/en/latest/terminology/plugin-config.md
index 95d69df0c..02ee1106a 100644
--- a/docs/en/latest/terminology/plugin-config.md
+++ b/docs/en/latest/terminology/plugin-config.md
@@ -60,7 +60,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 
'X-API-KEY: edd1c9f034335f13
 
 When APISIX can't find the Plugin Config with the `id`, the requests reaching 
this Route are terminated with a status code of 503.
 
-If a Route already has the `plugins` field configured, the plugins in the 
Plugin Config will effectively be merged to it. The same plugin in the Plugin 
Config will override the ones configured directly in the Route.
+If a Route already has the `plugins` field configured, the plugins in the 
Plugin Config will effectively be merged to it. The same plugin in the Plugin 
Config will not override the ones configured directly in the Route.
 
 For example, if we configure a Plugin Config as shown below
 
@@ -135,7 +135,7 @@ the effective configuration will be as the one shown below:
             "host": "apisix.iresty.com"
         },
         "limit-count": {
-            "count": 2,
+            "count": 20,
             "time_window": 60,
             "rejected_code": 503
         }
diff --git a/docs/zh/latest/architecture-design/plugin-config.md 
b/docs/zh/latest/architecture-design/plugin-config.md
index d3bac196e..171cda39b 100644
--- a/docs/zh/latest/architecture-design/plugin-config.md
+++ b/docs/zh/latest/architecture-design/plugin-config.md
@@ -56,7 +56,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 
'X-API-KEY: edd1c9f034335f
 如果找不到对应的 Plugin config,该路由上的请求会报 503 错误。
 
 如果这个路由已经配置了 `plugins`,那么 Plugin config 里面的插件配置会合并进去。
-相同的插件会覆盖掉 `plugins` 原有的插件。
+相同的插件不会覆盖掉 `plugins` 原有的插件。
 
 举个例子:
 
@@ -131,7 +131,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 
'X-API-KEY: edd1c9f034335f
             "host": "apisix.iresty.com"
         },
         "limit-count": {
-            "count": 2,
+            "count": 20,
             "time_window": 60,
             "rejected_code": 503
         }
diff --git a/t/config-center-yaml/plugin-configs.t 
b/t/config-center-yaml/plugin-configs.t
index e7a22b7ba..ab291d65e 100644
--- a/t/config-center-yaml/plugin-configs.t
+++ b/t/config-center-yaml/plugin-configs.t
@@ -113,7 +113,7 @@ routes:
 --- request
 GET /echo
 --- response_body
-hello
+world
 --- response_headers
 in: out
 --- error_log eval
diff --git a/t/node/plugin-configs.t b/t/node/plugin-configs.t
index 770392276..d6c0cb75c 100644
--- a/t/node/plugin-configs.t
+++ b/t/node/plugin-configs.t
@@ -249,3 +249,64 @@ property "block_rules" validation failed
 --- response_body
 hello
 hello world
+
+
+
+=== TEST 5: don't override the plugin in the route
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+
+            local code, err = t('/apisix/admin/plugin_configs/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "plugins": {
+                        "proxy-rewrite": {
+                            "uri": "/hello"
+                        },
+                        "response-rewrite": {
+                            "body": "hello"
+                        }
+                    }
+                }]]
+            )
+            if code > 300 then
+                ngx.log(ngx.ERR, err)
+                return
+            end
+
+            local code, err = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "uri": "/helloaa",
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "plugin_config_id": 1,
+                    "plugins": {
+                        "response-rewrite": {
+                            "body": "world"
+                        }
+                    }
+                }]]
+            )
+            if code > 300 then
+                ngx.log(ngx.ERR, err)
+                return
+            end
+            ngx.sleep(0.1)
+
+            local code, err, org_body = t('/helloaa')
+            if code > 300 then
+                ngx.log(ngx.ERR, err)
+                return
+            end
+            ngx.say(org_body)
+        }
+    }
+--- response_body
+world

Reply via email to