Skip to content

Commit ddac444

Browse files
authored
feat: add support for passing resolv.conf in dns discovery (apache#9770)
1 parent 299b525 commit ddac444

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

apisix/discovery/dns/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ end
6464
function _M.init_worker()
6565
local local_conf = config_local.local_conf()
6666
local servers = local_conf.discovery.dns.servers
67-
67+
local resolv_conf = local_conf.discovery.dns.resolv_conf
6868
local default_order = {"last", "SRV", "A", "AAAA", "CNAME"}
6969
local order = core.table.try_read_attr(local_conf, "discovery", "dns", "order")
7070
order = order or default_order
7171

7272
local opts = {
7373
hosts = {},
74-
resolvConf = {},
74+
resolvConf = resolv_conf,
7575
nameservers = servers,
7676
order = order,
7777
}

apisix/discovery/dns/schema.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ return {
2424
type = "string",
2525
},
2626
},
27+
resolv_conf = {
28+
type = "string",
29+
},
2730
order = {
2831
type = "array",
2932
minItems = 1,
@@ -34,5 +37,12 @@ return {
3437
},
3538
},
3639
},
37-
required = {"servers"}
40+
oneOf = {
41+
{
42+
required = {"servers"},
43+
},
44+
{
45+
required = {"resolv_conf"},
46+
}
47+
}
3848
}

ci/common.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ set_coredns() {
140140
pushd t/coredns || exit 1
141141
../../build-cache/coredns -dns.port=1053 &
142142
popd || exit 1
143+
144+
touch build-cache/test_resolve.conf
145+
echo "nameserver 127.0.0.1:1053" > build-cache/test_resolve.conf
143146
}
144147

145148
GRPC_SERVER_EXAMPLE_VER=20210819

conf/config-default.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ nginx_config: # Config for render the template to generate n
280280
# dns:
281281
# servers:
282282
# - "127.0.0.1:8600" # Replace with the address of your DNS server.
283+
# resolv_conf: /etc/resolv.conf # Replace with the path to the local DNS resolv config. Configure either "servers" or "resolv_conf".
283284
# order: # Resolve DNS records this order.
284285
# - last # Try the latest successful type for a hostname.
285286
# - SRV

t/discovery/dns/mix.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,4 @@ connect to 127.0.0.1:1053
128128
connect to 127.0.0.1:1053
129129
connect to 127.0.0.1:1053
130130
connect to 127.0.0.1:1053
131+
connect to 127.0.0.1:1053

t/discovery/dns/sanity.t

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,30 @@ upstreams:
434434
--- must_die
435435
--- error_log
436436
matches none of the enum values
437+
438+
439+
440+
=== TEST 20: use resolv.conf
441+
--- yaml_config
442+
apisix:
443+
node_listen: 1984
444+
enable_admin: false
445+
deployment:
446+
role: data_plane
447+
role_data_plane:
448+
config_provider: yaml
449+
discovery: # service discovery center
450+
dns:
451+
resolv_conf: build-cache/test_resolve.conf
452+
--- apisix_yaml
453+
upstreams:
454+
- service_name: "sd.test.local:1980"
455+
discovery_type: dns
456+
type: roundrobin
457+
id: 1
458+
--- grep_error_log eval
459+
qr/upstream nodes: \{[^}]+\}/
460+
--- grep_error_log_out eval
461+
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)\}/
462+
--- response_body
463+
hello world

0 commit comments

Comments
 (0)