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 2022/11/07 06:08:24 UTC
[apisix] branch master updated: feat: support connect etcd with ipv6 address (#8245)
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 4a8a91d63 feat: support connect etcd with ipv6 address (#8245)
4a8a91d63 is described below
commit 4a8a91d63a4ee1ae9f0e1fc7a438124e1380fdbb
Author: tzssangglass <tz...@gmail.com>
AuthorDate: Mon Nov 7 14:08:19 2022 +0800
feat: support connect etcd with ipv6 address (#8245)
Fixes https://github.com/apache/apisix/issues/7100
---
apisix/patch.lua | 12 +++++++++++-
rockspec/apisix-master-0.rockspec | 2 +-
t/cli/test_etcd.sh | 33 +++++++++++++++++++++++++++++++++
t/deployment/conf_server.t | 22 ++++++++++++++++++++++
4 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/apisix/patch.lua b/apisix/patch.lua
index 69506e659..2b191b2a8 100644
--- a/apisix/patch.lua
+++ b/apisix/patch.lua
@@ -201,6 +201,14 @@ local luasocket_wrapper = {
return self.sock:connect(path)
end
+ if host:byte(1) == string.byte('[') then
+ -- ipv6, form as '[::1]', remove '[' and ']'
+ host = host:sub(2, -2)
+ self.sock = self.tcp6
+ else
+ self.sock = self.tcp4
+ end
+
return self.sock:connect(host, port)
end,
@@ -349,7 +357,9 @@ local mt = {
local function luasocket_tcp()
local sock = socket.tcp()
- return setmetatable({sock = sock}, mt)
+ local tcp4 = socket.tcp4()
+ local tcp6 = socket.tcp6()
+ return setmetatable({sock = sock, tcp4 = tcp4, tcp6 = tcp6}, mt)
end
diff --git a/rockspec/apisix-master-0.rockspec b/rockspec/apisix-master-0.rockspec
index c9891de81..227d60071 100644
--- a/rockspec/apisix-master-0.rockspec
+++ b/rockspec/apisix-master-0.rockspec
@@ -63,7 +63,7 @@ dependencies = {
"lua-resty-expr = 1.3.2",
"graphql = 0.0.2",
"argparse = 0.7.1-1",
- "luasocket = 3.0rc1-2",
+ "luasocket = 3.1.0-1",
"luasec = 0.9-1",
"lua-resty-consul = 0.3-2",
"penlight = 1.9.2-1",
diff --git a/t/cli/test_etcd.sh b/t/cli/test_etcd.sh
index 033cab5be..be9b45f08 100755
--- a/t/cli/test_etcd.sh
+++ b/t/cli/test_etcd.sh
@@ -166,3 +166,36 @@ echo "passed: show password error successfully"
etcdctl --endpoints=127.0.0.1:2379 --user=root:apache-api6 auth disable
etcdctl --endpoints=127.0.0.1:2379 role delete root
etcdctl --endpoints=127.0.0.1:2379 user delete root
+
+# check connect to etcd with ipv6 address
+git checkout conf/config.yaml
+
+echo '
+deployment:
+ role: traditional
+ role_traditional:
+ config_provider: etcd
+ etcd:
+ host:
+ - http://[::1]:2379
+ prefix: /apisix
+ timeout: 30
+' > conf/config.yaml
+
+rm logs/error.log || true
+make run
+sleep 0.1
+
+if grep "update endpoint: http://\[::1\]:2379 to unhealthy" logs/error.log; then
+ echo "failed: connect to etcd via ipv6 address failed"
+ exit 1
+fi
+
+if grep "host or service not provided, or not known" logs/error.log; then
+ echo "failed: luasocket resolve ipv6 addresses failed"
+ exit 1
+fi
+
+make stop
+
+echo "passed: connect to etcd via ipv6 address successfully"
diff --git a/t/deployment/conf_server.t b/t/deployment/conf_server.t
index b440591e9..c6869b829 100644
--- a/t/deployment/conf_server.t
+++ b/t/deployment/conf_server.t
@@ -447,3 +447,25 @@ deployment:
- http://127.0.0.1:2379
--- response_body
30
+
+
+
+=== TEST 11: ipv6
+--- config
+ location /t {
+ content_by_lua_block {
+ local etcd = require("apisix.core.etcd")
+ assert(etcd.set("/apisix/test", "foo"))
+ local res = assert(etcd.get("/apisix/test"))
+ ngx.say(res.body.node.value)
+ }
+ }
+--- yaml_config
+deployment:
+ role: traditional
+ role_traditional:
+ config_provider: etcd
+ etcd:
+ prefix: "/apisix"
+ host:
+ - http://[::1]:2379