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/04/13 00:54:44 UTC

[apisix] branch master updated: fix(standalone): the conf should be available during start (#4027)

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 3cde740  fix(standalone): the conf should be available during start (#4027)
3cde740 is described below

commit 3cde7408386febeb92f6b47192c82990532dfd51
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Tue Apr 13 08:54:36 2021 +0800

    fix(standalone): the conf should be available during start (#4027)
---
 apisix/core/config_yaml.lua | 10 ++++++++++
 apisix/init.lua             |  2 +-
 apisix/plugin.lua           | 20 ++++++++++----------
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/apisix/core/config_yaml.lua b/apisix/core/config_yaml.lua
index fbf3106..e8eabb6 100644
--- a/apisix/core/config_yaml.lua
+++ b/apisix/core/config_yaml.lua
@@ -332,6 +332,16 @@ function _M.new(key, opts)
             return nil, "missing `key` argument"
         end
 
+        local ok, ok2, err = pcall(sync_data, obj)
+        if not ok then
+            err = ok2
+        end
+
+        if err then
+            log.error("failed to fetch data from local file ", apisix_yaml_path, ": ",
+                      err, ", ", key)
+        end
+
         ngx_timer_at(0, _automatic_fetch, obj)
     end
 
diff --git a/apisix/init.lua b/apisix/init.lua
index 2fea841..d71fd70 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -718,8 +718,8 @@ function _M.stream_init_worker()
     -- for testing only
     core.log.info("random stream test in [1, 10000]: ", math.random(1, 10000))
 
-    router.stream_init_worker()
     plugin.init_worker()
+    router.stream_init_worker()
 
     if core.config == require("apisix.core.config_yaml") then
         core.config.init_worker()
diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index ea0a54b..8af3dd7 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -267,14 +267,12 @@ function _M.load(config)
         -- called during synchronizing plugin data
         http_plugin_names = {}
         stream_plugin_names = {}
-        for _, conf_value in config_util.iterate_values(config.values) do
-            local plugins_conf = conf_value.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)
-                end
+        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)
             end
         end
     end
@@ -486,8 +484,10 @@ do
             automatic = true,
             item_schema = core.schema.plugins,
             single_item = true,
-            filter = function()
-                _M.load(plugins_conf)
+            filter = function(item)
+                -- we need to pass 'item' instead of plugins_conf because
+                -- the latter one is nil at the first run
+                _M.load(item)
             end,
         })
         if not plugins_conf then