You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by mo...@apache.org on 2023/09/26 03:58:53 UTC
[apisix] branch master updated: feat: add support for passing resolv.conf in dns discovery (#9770)
This is an automated email from the ASF dual-hosted git repository.
monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new ddac44442 feat: add support for passing resolv.conf in dns discovery (#9770)
ddac44442 is described below
commit ddac444421dd20b45a78a232f558d364b6fb3fdd
Author: Ashish Tiwari <as...@gmail.com>
AuthorDate: Tue Sep 26 09:28:48 2023 +0530
feat: add support for passing resolv.conf in dns discovery (#9770)
---
apisix/discovery/dns/init.lua | 4 ++--
apisix/discovery/dns/schema.lua | 12 +++++++++++-
ci/common.sh | 3 +++
conf/config-default.yaml | 1 +
t/discovery/dns/mix.t | 1 +
t/discovery/dns/sanity.t | 27 +++++++++++++++++++++++++++
6 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/apisix/discovery/dns/init.lua b/apisix/discovery/dns/init.lua
index 609ad5ea1..601de0ebc 100644
--- a/apisix/discovery/dns/init.lua
+++ b/apisix/discovery/dns/init.lua
@@ -64,14 +64,14 @@ end
function _M.init_worker()
local local_conf = config_local.local_conf()
local servers = local_conf.discovery.dns.servers
-
+ local resolv_conf = local_conf.discovery.dns.resolv_conf
local default_order = {"last", "SRV", "A", "AAAA", "CNAME"}
local order = core.table.try_read_attr(local_conf, "discovery", "dns", "order")
order = order or default_order
local opts = {
hosts = {},
- resolvConf = {},
+ resolvConf = resolv_conf,
nameservers = servers,
order = order,
}
diff --git a/apisix/discovery/dns/schema.lua b/apisix/discovery/dns/schema.lua
index 989938ab1..03c7934ae 100644
--- a/apisix/discovery/dns/schema.lua
+++ b/apisix/discovery/dns/schema.lua
@@ -24,6 +24,9 @@ return {
type = "string",
},
},
+ resolv_conf = {
+ type = "string",
+ },
order = {
type = "array",
minItems = 1,
@@ -34,5 +37,12 @@ return {
},
},
},
- required = {"servers"}
+ oneOf = {
+ {
+ required = {"servers"},
+ },
+ {
+ required = {"resolv_conf"},
+ }
+ }
}
diff --git a/ci/common.sh b/ci/common.sh
index e1961fc6b..3ad1e651c 100644
--- a/ci/common.sh
+++ b/ci/common.sh
@@ -140,6 +140,9 @@ set_coredns() {
pushd t/coredns || exit 1
../../build-cache/coredns -dns.port=1053 &
popd || exit 1
+
+ touch build-cache/test_resolve.conf
+ echo "nameserver 127.0.0.1:1053" > build-cache/test_resolve.conf
}
GRPC_SERVER_EXAMPLE_VER=20210819
diff --git a/conf/config-default.yaml b/conf/config-default.yaml
index f15f6d1df..09c459677 100755
--- a/conf/config-default.yaml
+++ b/conf/config-default.yaml
@@ -280,6 +280,7 @@ nginx_config: # Config for render the template to generate n
# dns:
# servers:
# - "127.0.0.1:8600" # Replace with the address of your DNS server.
+# resolv_conf: /etc/resolv.conf # Replace with the path to the local DNS resolv config. Configure either "servers" or "resolv_conf".
# order: # Resolve DNS records this order.
# - last # Try the latest successful type for a hostname.
# - SRV
diff --git a/t/discovery/dns/mix.t b/t/discovery/dns/mix.t
index 6453b5c37..e84994298 100644
--- a/t/discovery/dns/mix.t
+++ b/t/discovery/dns/mix.t
@@ -128,3 +128,4 @@ connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
+connect to 127.0.0.1:1053
diff --git a/t/discovery/dns/sanity.t b/t/discovery/dns/sanity.t
index c26eceeba..4e0eaa7ae 100644
--- a/t/discovery/dns/sanity.t
+++ b/t/discovery/dns/sanity.t
@@ -434,3 +434,30 @@ upstreams:
--- must_die
--- error_log
matches none of the enum values
+
+
+
+=== TEST 20: use resolv.conf
+--- yaml_config
+apisix:
+ node_listen: 1984
+ enable_admin: false
+deployment:
+ role: data_plane
+ role_data_plane:
+ config_provider: yaml
+discovery: # service discovery center
+ dns:
+ resolv_conf: build-cache/test_resolve.conf
+--- apisix_yaml
+upstreams:
+ - service_name: "sd.test.local:1980"
+ discovery_type: dns
+ type: roundrobin
+ id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- response_body
+hello world