Skip to content

Commit

Permalink
fix(cmd) do not reload the declarative config on kong reload if no de…
Browse files Browse the repository at this point in the history
…clarative config given

### Summary

On `kong reload` we do not want to reload the declarative configuration that was given on e.g.
`kong start` (because that could overwrite the more recent configuration send to `:8000/config`).
Thus we want to clear the declarative config from the `.kong_env` before we reload a new
configuration.
  • Loading branch information
bungle committed Dec 22, 2020
1 parent f85311d commit 9529f8c
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 4 deletions.
4 changes: 4 additions & 0 deletions kong/cmd/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ local function execute(args)
prefix = args.prefix
}))

if not new_config.declarative_config then
conf.declarative_config = nil
end

assert(prefix_handler.prepare_prefix(conf, args.nginx_conf))
assert(nginx_signals.reload(conf))

Expand Down
108 changes: 104 additions & 4 deletions spec/02-integration/02-cmd/03-reload_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ describe("kong reload #" .. strategy, function()
- example.test
]], yaml_file)

assert(kong_reload(strategy, "reload --prefix " .. helpers.test_conf.prefix))
assert(kong_reload(strategy, "reload --prefix " .. helpers.test_conf.prefix, {
declarative_config = yaml_file,
}))

helpers.wait_until(function()
pok, admin_client = pcall(helpers.admin_client)
Expand Down Expand Up @@ -384,7 +386,102 @@ describe("kong reload #" .. strategy, function()
return true
end)

assert(kong_reload(strategy, "reload --prefix " .. helpers.test_conf.prefix))

admin_client = assert(helpers.admin_client())
local res = assert(admin_client:send {
method = "GET",
path = "/services",
})
assert.res_status(200, res)

local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.same(1, #json.data)
assert.same(ngx.null, json.next)
admin_client:close()

return "my-service" == json.data[1].name
end)

it("preserves declarative config from memory even when kong was started with a declarative_config", function()
local yaml_file = helpers.make_yaml_file [[
_format_version: "1.1"
services:
- name: my-service-on-start
url: http://127.0.0.1:15555
routes:
- name: example-route
hosts:
- example.test
]]

local pok, admin_client

finally(function()
helpers.stop_kong(helpers.test_conf.prefix, true)
if admin_client then
admin_client:close()
end
end)

assert(helpers.start_kong({
database = "off",
nginx_worker_processes = 1,
declarative_config = yaml_file,
nginx_conf = "spec/fixtures/custom_nginx.template",
}))

helpers.wait_until(function()
pok, admin_client = pcall(helpers.admin_client)
if not pok then
return false
end

local res = assert(admin_client:send {
method = "GET",
path = "/services",
})
assert.res_status(200, res)

local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.same(1, #json.data)
assert.same(ngx.null, json.next)

admin_client:close()

return "my-service-on-start" == json.data[1].name
end, 10)

helpers.wait_until(function()
pok, admin_client = pcall(helpers.admin_client)
if not pok then
return false
end

local res = assert(admin_client:send {
method = "POST",
path = "/config",
headers = {
["Content-Type"] = "application/json",
},
body = {
_format_version = "1.1",
services = {
{
name = "my-service",
url = "http://127.0.0.1:15555",
}
}
},
}, 10)
assert.res_status(201, res)

admin_client:close()

return true
end)

assert(kong_reload(strategy, "reload --prefix " .. helpers.test_conf.prefix))

Expand Down Expand Up @@ -477,7 +574,9 @@ describe("kong reload #" .. strategy, function()
weight: 100
]], yaml_file)

assert(kong_reload(strategy, "reload --prefix " .. helpers.test_conf.prefix))
assert(kong_reload(strategy, "reload --prefix " .. helpers.test_conf.prefix, {
declarative_config = yaml_file,
}))

helpers.wait_until(function()
pok, admin_client = pcall(helpers.admin_client)
Expand Down Expand Up @@ -608,8 +707,9 @@ describe("key-auth plugin invalidation on dbless reload #off", function()
keyauth_credentials:
- key: my-new-key
]], yaml_file)
assert(kong_reload("off", "reload --prefix " .. helpers.test_conf.prefix))

assert(kong_reload("off", "reload --prefix " .. helpers.test_conf.prefix, {
declarative_config = yaml_file,
}))

local res

Expand Down

0 comments on commit 9529f8c

Please sign in to comment.