Skip to content

Commit e185c88

Browse files
fix(clustering): lmdb cache should prioritize over declaritive config
fix #14407, KAG-6852
1 parent d1a8e41 commit e185c88

File tree

2 files changed

+74
-4
lines changed

2 files changed

+74
-4
lines changed

kong/init.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,8 @@ function Kong.init_worker()
921921
return
922922
end
923923

924-
if not has_declarative_config(kong.configuration) and
925-
declarative.get_current_hash() ~= nil then
926-
-- if there is no declarative config set and a config is present in LMDB,
924+
if declarative.get_current_hash() ~= nil then
925+
-- a config is present in LMDB,
927926
-- just build the router and plugins iterator
928927
ngx_log(ngx_INFO, "found persisted lmdb config, loading...")
929928
local ok, err = declarative_init_build()

spec/02-integration/09-hybrid_mode/02-start_stop_spec.lua

+72-1
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,75 @@ describe("when CP exits before DP" .. " rpc_sync=" .. rpc_sync, function()
223223
assert.logfile("servroot2/logs/error.log").has.no.line("error while receiving frame from peer", true)
224224
end)
225225
end)
226-
end -- for rpc_sync
226+
227+
describe("DP config cache", function()
228+
it("DP config cache should prioritize over declaritive config #regression", function ()
229+
local cjson = require "cjson"
230+
local config1 = cjson.encode {
231+
_format_version = "1.1",
232+
services = {
233+
{
234+
name = "my-service",
235+
url = "http://127.0.0.1:15555",
236+
routes = {
237+
{
238+
name = "example-route",
239+
hosts = { "example.test" }
240+
}
241+
}
242+
}
243+
}
244+
}
245+
246+
247+
local config2 = cjson.encode {
248+
_format_version = "1.1",
249+
}
250+
251+
252+
assert.truthy(helpers.start_kong({
253+
role = "data_plane",
254+
database = "off",
255+
nginx_conf = "spec/fixtures/custom_nginx.template",
256+
prefix = "servroot2",
257+
cluster_rpc = rpc,
258+
cluster_rpc_sync = rpc_sync,
259+
declarative_config_string = config1,
260+
proxy_listen = "0.0.0.0:9002",
261+
}))
262+
263+
-- do not clean the prefix to preserve the config cache
264+
helpers.stop_kong("servroot2", true)
265+
266+
assert(helpers.start_kong({
267+
role = "data_plane",
268+
database = "off",
269+
nginx_conf = "spec/fixtures/custom_nginx.template",
270+
prefix = "servroot2",
271+
cluster_rpc = rpc,
272+
cluster_rpc_sync = rpc_sync,
273+
declarative_config_string = config2,
274+
}))
275+
276+
finally(function()
277+
-- stop the data plane
278+
helpers.stop_kong("servroot2")
279+
end)
280+
281+
local proxy_client = assert(helpers.proxy_client({
282+
prefix = "servroot2",
283+
port = 9002,
284+
}))
285+
286+
-- it should use the config cache
287+
assert.res_status(200, proxy_client:send({
288+
method = "GET",
289+
path = "/",
290+
headers = {
291+
host = "example.test",
292+
},
293+
}))
294+
end)
295+
end)
296+
297+
end -- for rpc_sync

0 commit comments

Comments
 (0)