Skip to content

Commit

Permalink
fix(standalone): the conf should be available during start (apache#4027)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored Apr 13, 2021
1 parent a57408d commit 3cde740
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
10 changes: 10 additions & 0 deletions apisix/core/config_yaml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 10 additions & 10 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3cde740

Please sign in to comment.