Skip to content

Commit

Permalink
fix(dns): change dns client switch to new_dns_client
Browse files Browse the repository at this point in the history
  • Loading branch information
chobits committed Aug 15, 2024
1 parent b45233d commit 1c2e673
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 20 deletions.
4 changes: 1 addition & 3 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -1542,9 +1542,7 @@
# It provides observable statistics, you can retrieve them through the Admin API
# `/status/dns`.

#legacy_dns_client = off # Disable the new DNS resolver, using the
# original DNS resolver. See above `dns_xxx`
# options for the original DNS resolver.
#new_dns_client = on # Enable the new DNS resolver

#resolver_address = <name servers parsed from resolv.conf>
# Comma-separated list of nameservers, each
Expand Down
2 changes: 1 addition & 1 deletion kong/api/routes/dns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ return {
["/status/dns"] = {
GET = function (self, db, helpers)

if kong.configuration.legacy_dns_client then
if not kong.configuration.new_dns_client then
return kong.response.exit(501, {
message = "not implemented with the legacy DNS client"
})
Expand Down
2 changes: 1 addition & 1 deletion kong/api/routes/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ return {
},
["/status/dns"] = {
GET = function (self, db, helpers)
if kong.configuration.legacy_dns_client then
if not kong.configuration.new_dns_client then
return kong.response.exit(501, { message = "not implemented with the legacy DNS client" })
end

Expand Down
2 changes: 1 addition & 1 deletion kong/conf_loader/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ local CONF_PARSERS = {
dns_error_ttl = { typ = "number" },
dns_no_sync = { typ = "boolean" },

legacy_dns_client = { typ = "boolean" },
new_dns_client = { typ = "boolean" },

resolver_address = { typ = "array" },
resolver_hosts_file = { typ = "string" },
Expand Down
4 changes: 2 additions & 2 deletions kong/resty/dns/client.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Use the new dns client library instead. If you want to switch to the original
-- one, you can set `legacy_dns_client = on` in kong.conf.
if ngx.shared.kong_dns_cache and not _G.busted_legacy_dns_client then
-- one, you can set `new_dns_client = off` in kong.conf.
if ngx.shared.kong_dns_cache and _G.busted_new_dns_client then
package.loaded["kong.dns.client"] = nil
return require("kong.dns.client")
end
Expand Down
2 changes: 1 addition & 1 deletion kong/templates/kong_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ dns_not_found_ttl = 30
dns_error_ttl = 1
dns_no_sync = off
legacy_dns_client = off
new_dns_client = on
resolver_address = NONE
resolver_hosts_file = /etc/hosts
Expand Down
2 changes: 1 addition & 1 deletion kong/templates/nginx_kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lua_shared_dict kong_db_cache ${{MEM_CACHE_SIZE}};
lua_shared_dict kong_db_cache_miss 12m;
lua_shared_dict kong_secrets 5m;
> if not legacy_dns_client then
> if new_dns_client then
lua_shared_dict kong_dns_cache ${{RESOLVER_MEM_CACHE_SIZE}};
> end
Expand Down
2 changes: 1 addition & 1 deletion kong/tools/dns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ local setup_client = function(conf)
}

-- new dns client
if ngx.shared.kong_dns_cache and not _G.busted_legacy_dns_client then
if ngx.shared.kong_dns_cache and _G.busted_new_dns_client then

servers = {}

Expand Down
2 changes: 0 additions & 2 deletions spec/01-unit/21-dns-client/02-client_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe("[DNS client]", function()
local client, resolver

before_each(function()
_G.busted_legacy_dns_client = true
client = require("kong.resty.dns.client")
resolver = require("resty.dns.resolver")

Expand Down Expand Up @@ -72,7 +71,6 @@ describe("[DNS client]", function()
end)

after_each(function()
_G.busted_legacy_dns_client = nil
package.loaded["kong.resty.dns.client"] = nil
package.loaded["resty.dns.resolver"] = nil
client = nil
Expand Down
2 changes: 0 additions & 2 deletions spec/01-unit/21-dns-client/03-client_cache_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe("[DNS client cache]", function()
local client, resolver

before_each(function()
_G.busted_legacy_dns_client = true
client = require("kong.resty.dns.client")
resolver = require("resty.dns.resolver")

Expand Down Expand Up @@ -56,7 +55,6 @@ describe("[DNS client cache]", function()
end)

after_each(function()
_G.busted_legacy_dns_client = nil
package.loaded["kong.resty.dns.client"] = nil
package.loaded["resty.dns.resolver"] = nil
client = nil
Expand Down
2 changes: 1 addition & 1 deletion spec/01-unit/30-new-dns-client/04-client_ipc_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("[dns-client] inter-process communication:",function()
nginx_conf = "spec/fixtures/custom_nginx.template",
plugins = "bundled,dns-client-test",
nginx_main_worker_processes = num_workers,
legacy_dns_client = "off",
new_dns_client = "on",
}))
end)

Expand Down
8 changes: 4 additions & 4 deletions spec/02-integration/08-status_api/05-dns_client_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ for _, strategy in helpers.each_strategy() do
assert(helpers.start_kong({
database = strategy,
status_listen = "127.0.0.1:" .. tcp_status_port,
legacy_dns_client = "off",
new_dns_client = "on",
}))

client = helpers.http_client("127.0.0.1", tcp_status_port, 20000)
Expand Down Expand Up @@ -75,7 +75,7 @@ for _, strategy in helpers.each_strategy() do
assert(helpers.start_kong({
database = strategy,
status_listen = "127.0.0.1:" .. tcp_status_port,
legacy_dns_client = "on",
new_dns_client = "off",
}))

client = helpers.http_client("127.0.0.1", tcp_status_port, 20000)
Expand Down Expand Up @@ -120,7 +120,7 @@ for _, strategy in helpers.each_strategy() do
database = strategy,
cluster_listen = "127.0.0.1:9005",
nginx_conf = "spec/fixtures/custom_nginx.template",
legacy_dns_client = "off",
new_dns_client = "on",
}))

assert(helpers.start_kong({
Expand All @@ -133,7 +133,7 @@ for _, strategy in helpers.each_strategy() do
proxy_listen = "0.0.0.0:9002",
nginx_conf = "spec/fixtures/custom_nginx.template",
status_listen = "127.0.0.1:" .. tcp_status_port,
legacy_dns_client = "off",
new_dns_client = "on",
}))

client = helpers.http_client("127.0.0.1", tcp_status_port, 20000)
Expand Down

0 comments on commit 1c2e673

Please sign in to comment.