You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/02/05 01:00:31 UTC
[apisix] branch master updated: feat: support DNS AAAA record
(#3484)
This is an automated email from the ASF dual-hosted git repository.
spacewander 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 e1dbe2c feat: support DNS AAAA record (#3484)
e1dbe2c is described below
commit e1dbe2c4a49be08f6e280ee18167a172c7e92650
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Fri Feb 5 09:00:20 2021 +0800
feat: support DNS AAAA record (#3484)
---
.travis/linux_openresty_common_runner.sh | 2 +-
apisix/core/utils.lua | 7 ++-
t/APISIX.pm | 21 +++++++++
t/core/etcd-auth-fail.t | 3 +-
t/core/etcd-auth.t | 3 +-
t/coredns/Corefile | 4 ++
t/coredns/db.test.local | 13 ++++++
t/node/upstream-domain-with-special-dns.t | 71 +++++++++++++++++++++++++++++++
utils/centos7-ci.sh | 2 +-
utils/set-dns.sh | 14 ++++++
10 files changed, 132 insertions(+), 8 deletions(-)
diff --git a/.travis/linux_openresty_common_runner.sh b/.travis/linux_openresty_common_runner.sh
index fe50864..55d42da 100755
--- a/.travis/linux_openresty_common_runner.sh
+++ b/.travis/linux_openresty_common_runner.sh
@@ -142,7 +142,7 @@ script() {
make lint && make license-check || exit 1
# APISIX_ENABLE_LUACOV=1 PERL5LIB=.:$PERL5LIB prove -Itest-nginx/lib -r t
- PERL5LIB=.:$PERL5LIB prove -Itest-nginx/lib -r t
+ FLUSH_ETCD=1 PERL5LIB=.:$PERL5LIB prove -Itest-nginx/lib -r t
}
after_success() {
diff --git a/apisix/core/utils.lua b/apisix/core/utils.lua
index 60e3068..21a40b1 100644
--- a/apisix/core/utils.lua
+++ b/apisix/core/utils.lua
@@ -16,6 +16,7 @@
--
local core_str = require("apisix.core.string")
local table = require("apisix.core.table")
+local json = require("apisix.core.json")
local log = require("apisix.core.log")
local string = require("apisix.core.string")
local ngx_re = require("ngx.re")
@@ -98,8 +99,6 @@ local function dns_parse(domain)
current_inited_resolvers = dns_resolvers
end
- log.info("dns resolve ", domain)
-
-- this function will dereference the CNAME records
local answers, err = dns_client.resolve(domain)
if not answers then
@@ -114,8 +113,8 @@ local function dns_parse(domain)
local idx = math.random(1, #answers)
local answer = answers[idx]
local dns_type = answer.type
- -- TODO: support AAAA & SRV
- if dns_type == dns_client.TYPE_A then
+ if dns_type == dns_client.TYPE_A or dns_type == dns_client.TYPE_AAAA then
+ log.info("dns resolve ", domain, ", result: ", json.delay_encode(answer))
return table.deepcopy(answer)
end
diff --git a/t/APISIX.pm b/t/APISIX.pm
index 90417e1..618443b 100644
--- a/t/APISIX.pm
+++ b/t/APISIX.pm
@@ -69,6 +69,10 @@ if ($enable_local_dns) {
$dns_addrs_str = "8.8.8.8 114.114.114.114";
$dns_addrs_tbl_str = "{\"8.8.8.8\", \"114.114.114.114\"}";
}
+my $custom_dns_server = $ENV{"CUSTOM_DNS_SERVER"};
+if ($custom_dns_server) {
+ $dns_addrs_tbl_str = "{\"$custom_dns_server\"}";
+}
my $default_yaml_config = read_file("conf/config-default.yaml");
@@ -634,4 +638,21 @@ _EOC_
$block;
});
+sub run_or_exit ($) {
+ my ($cmd) = @_;
+ my $output = `$cmd`;
+ if ($?) {
+ warn "$output";
+ exit 1;
+ }
+}
+
+add_cleanup_handler(sub {
+ if ($ENV{FLUSH_ETCD}) {
+ delete $ENV{APISIX_PROFILE};
+ run_or_exit "etcdctl del --prefix /apisix";
+ run_or_exit "./bin/apisix init_etcd";
+ }
+});
+
1;
diff --git a/t/core/etcd-auth-fail.t b/t/core/etcd-auth-fail.t
index 5b3d704..e04eca8 100644
--- a/t/core/etcd-auth-fail.t
+++ b/t/core/etcd-auth-fail.t
@@ -15,7 +15,8 @@
# limitations under the License.
#
BEGIN {
- $ENV{"ETCD_ENABLE_AUTH"} = "false"
+ $ENV{"ETCD_ENABLE_AUTH"} = "false";
+ delete $ENV{"FLUSH_ETCD"};
}
use t::APISIX 'no_plan';
diff --git a/t/core/etcd-auth.t b/t/core/etcd-auth.t
index 794013a..e83fb9c 100644
--- a/t/core/etcd-auth.t
+++ b/t/core/etcd-auth.t
@@ -15,7 +15,8 @@
# limitations under the License.
#
BEGIN {
- $ENV{"ETCD_ENABLE_AUTH"} = "true"
+ $ENV{"ETCD_ENABLE_AUTH"} = "true";
+ delete $ENV{"FLUSH_ETCD"};
}
use t::APISIX 'no_plan';
diff --git a/t/coredns/Corefile b/t/coredns/Corefile
new file mode 100644
index 0000000..53dad79
--- /dev/null
+++ b/t/coredns/Corefile
@@ -0,0 +1,4 @@
+test.local {
+ file db.test.local
+ log
+}
diff --git a/t/coredns/db.test.local b/t/coredns/db.test.local
new file mode 100644
index 0000000..1c406bf
--- /dev/null
+++ b/t/coredns/db.test.local
@@ -0,0 +1,13 @@
+$ORIGIN test.local.
+@ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. (
+ 2017042745 ; serial
+ 7200 ; refresh (2 hours)
+ 3600 ; retry (1 hour)
+ 1209600 ; expire (2 weeks)
+ 3600 ; minimum (1 hour)
+ )
+
+ 3600 IN NS a.iana-servers.net.
+ 3600 IN NS b.iana-servers.net.
+
+ipv6 IN AAAA ::1
diff --git a/t/node/upstream-domain-with-special-dns.t b/t/node/upstream-domain-with-special-dns.t
new file mode 100644
index 0000000..e968ec8
--- /dev/null
+++ b/t/node/upstream-domain-with-special-dns.t
@@ -0,0 +1,71 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+BEGIN {
+ $ENV{CUSTOM_DNS_SERVER} = "127.0.0.1:1053";
+}
+
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+log_level('info');
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ my $yaml_config = $block->yaml_config // <<_EOC_;
+apisix:
+ node_listen: 1984
+ config_center: yaml
+ enable_admin: false
+_EOC_
+
+ $block->set_value("yaml_config", $yaml_config);
+
+ my $routes = <<_EOC_;
+routes:
+ -
+ uri: /hello
+ upstream_id: 1
+#END
+_EOC_
+
+ $block->set_value("apisix_yaml", $block->apisix_yaml . $routes);
+
+ if (!$block->error_log && !$block->no_error_log) {
+ $block->set_value("no_error_log", "[error]");
+ }
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+ -
+ id: 1
+ nodes:
+ ipv6.test.local:1980: 1
+ type: roundrobin
+--- request
+GET /hello
+--- response_body
+hello world
diff --git a/utils/centos7-ci.sh b/utils/centos7-ci.sh
index 9ef6f85..d0065ac 100755
--- a/utils/centos7-ci.sh
+++ b/utils/centos7-ci.sh
@@ -64,7 +64,7 @@ run_case() {
export_or_prefix
./utils/set-dns.sh
# run test cases
- prove -I./test-nginx/lib -I./ -r -s t/
+ FLUSH_ETCD=1 prove -I./test-nginx/lib -I./ -r t/
}
case_opt=$1
diff --git a/utils/set-dns.sh b/utils/set-dns.sh
index 618b033..1d6ae40 100755
--- a/utils/set-dns.sh
+++ b/utils/set-dns.sh
@@ -24,3 +24,17 @@ cat /etc/hosts # check GitHub Action's configuration
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
echo "search apache.org" | sudo tee -a /etc/resolv.conf
+
+mkdir -p build-cache
+
+if [ ! -f "build-cache/coredns_1_8_1" ]; then
+ wget https://github.com/coredns/coredns/releases/download/v1.8.1/coredns_1.8.1_linux_amd64.tgz
+ tar -xvf coredns_1.8.1_linux_amd64.tgz
+ mv coredns build-cache/
+
+ touch build-cache/coredns_1_8_1
+fi
+
+pushd t/coredns || exit 1
+../../build-cache/coredns -dns.port=1053 &
+popd || exit 1