From 1c2e6737b07ae76aff6af7166779f666d04cd61c Mon Sep 17 00:00:00 2001 From: Xiaochen Wang Date: Thu, 15 Aug 2024 17:15:55 +0800 Subject: [PATCH] fix(dns): change dns client switch to `new_dns_client` --- kong.conf.default | 4 +--- kong/api/routes/dns.lua | 2 +- kong/api/routes/kong.lua | 2 +- kong/conf_loader/constants.lua | 2 +- kong/resty/dns/client.lua | 4 ++-- kong/templates/kong_defaults.lua | 2 +- kong/templates/nginx_kong.lua | 2 +- kong/tools/dns.lua | 2 +- spec/01-unit/21-dns-client/02-client_spec.lua | 2 -- spec/01-unit/21-dns-client/03-client_cache_spec.lua | 2 -- spec/01-unit/30-new-dns-client/04-client_ipc_spec.lua | 2 +- spec/02-integration/08-status_api/05-dns_client_spec.lua | 8 ++++---- 12 files changed, 14 insertions(+), 20 deletions(-) diff --git a/kong.conf.default b/kong.conf.default index 284fd13894db3..00201c158fc27 100644 --- a/kong.conf.default +++ b/kong.conf.default @@ -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 = # Comma-separated list of nameservers, each diff --git a/kong/api/routes/dns.lua b/kong/api/routes/dns.lua index 37892a74b21a7..cdd022f69750b 100644 --- a/kong/api/routes/dns.lua +++ b/kong/api/routes/dns.lua @@ -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" }) diff --git a/kong/api/routes/kong.lua b/kong/api/routes/kong.lua index 633083a6d5fb1..6ade907bc1924 100644 --- a/kong/api/routes/kong.lua +++ b/kong/api/routes/kong.lua @@ -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 diff --git a/kong/conf_loader/constants.lua b/kong/conf_loader/constants.lua index 894d80df3d7e6..7b233c9ff942d 100644 --- a/kong/conf_loader/constants.lua +++ b/kong/conf_loader/constants.lua @@ -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" }, diff --git a/kong/resty/dns/client.lua b/kong/resty/dns/client.lua index a5872227ff914..dc96067bf18fc 100644 --- a/kong/resty/dns/client.lua +++ b/kong/resty/dns/client.lua @@ -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 diff --git a/kong/templates/kong_defaults.lua b/kong/templates/kong_defaults.lua index 153a61ad076c3..a5e71c627d968 100644 --- a/kong/templates/kong_defaults.lua +++ b/kong/templates/kong_defaults.lua @@ -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 diff --git a/kong/templates/nginx_kong.lua b/kong/templates/nginx_kong.lua index a02336697f76a..98f4bd2ba6201 100644 --- a/kong/templates/nginx_kong.lua +++ b/kong/templates/nginx_kong.lua @@ -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 diff --git a/kong/tools/dns.lua b/kong/tools/dns.lua index 22f32a8f9c1e7..1635be7bfbebe 100644 --- a/kong/tools/dns.lua +++ b/kong/tools/dns.lua @@ -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 = {} diff --git a/spec/01-unit/21-dns-client/02-client_spec.lua b/spec/01-unit/21-dns-client/02-client_spec.lua index e5a88c8e8d9cb..acd597ec2ec29 100644 --- a/spec/01-unit/21-dns-client/02-client_spec.lua +++ b/spec/01-unit/21-dns-client/02-client_spec.lua @@ -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") @@ -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 diff --git a/spec/01-unit/21-dns-client/03-client_cache_spec.lua b/spec/01-unit/21-dns-client/03-client_cache_spec.lua index 448bd8b8a923a..eb57d1ec2a248 100644 --- a/spec/01-unit/21-dns-client/03-client_cache_spec.lua +++ b/spec/01-unit/21-dns-client/03-client_cache_spec.lua @@ -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") @@ -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 diff --git a/spec/01-unit/30-new-dns-client/04-client_ipc_spec.lua b/spec/01-unit/30-new-dns-client/04-client_ipc_spec.lua index 5ed287def1dfe..63f50a156eac7 100644 --- a/spec/01-unit/30-new-dns-client/04-client_ipc_spec.lua +++ b/spec/01-unit/30-new-dns-client/04-client_ipc_spec.lua @@ -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) diff --git a/spec/02-integration/08-status_api/05-dns_client_spec.lua b/spec/02-integration/08-status_api/05-dns_client_spec.lua index 8ebeb757e645f..a3e7108a5b9e0 100644 --- a/spec/02-integration/08-status_api/05-dns_client_spec.lua +++ b/spec/02-integration/08-status_api/05-dns_client_spec.lua @@ -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) @@ -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) @@ -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({ @@ -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)