Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support etcd v3, by mocking v2 API #2036

Merged
merged 79 commits into from Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
e76c285
feat: support etcd v3 by mock v2 api
Yiyiyimu Aug 10, 2020
c710b23
fix: lint
Yiyiyimu Aug 10, 2020
c5a200a
avoid lib lbase64 error
Yiyiyimu Aug 10, 2020
913c744
support etcd v3.2, multiversion WIP
Yiyiyimu Aug 11, 2020
a2b93d3
fix travis files
Yiyiyimu Aug 11, 2020
2597b4f
test for ETCDCTL_API position
Yiyiyimu Aug 11, 2020
82fd940
fix: license check typo
Yiyiyimu Aug 11, 2020
e91ccf5
fix: converted index tonumber
Yiyiyimu Aug 11, 2020
a14ff1b
fix typo
Yiyiyimu Aug 11, 2020
3c6480e
only first set return status 201, others return 200
Yiyiyimu Aug 11, 2020
c85d86a
fix v3 watch would not return all changes
Yiyiyimu Aug 16, 2020
c29a210
fix unnecessary change
Yiyiyimu Aug 16, 2020
479573f
fix lint
Yiyiyimu Aug 16, 2020
354219d
retest
Yiyiyimu Aug 17, 2020
e18d3ed
v2/v3 CI; test ETCDCTL_API
Yiyiyimu Aug 17, 2020
c5993dc
use luaposix to set environment variable ETCDCTL_API
Yiyiyimu Aug 17, 2020
d3ecb45
fix license-check
Yiyiyimu Aug 17, 2020
97809d8
env var test
Yiyiyimu Aug 17, 2020
2e771c7
support v3 only
Yiyiyimu Aug 22, 2020
e2d48cb
merge master
Yiyiyimu Aug 22, 2020
330135a
remove etcd v2 in github actions
Yiyiyimu Aug 22, 2020
e8cfaab
fix typo
Yiyiyimu Aug 22, 2020
95e8bed
fix format and doc
Yiyiyimu Aug 22, 2020
bcba1b8
fix format
Yiyiyimu Aug 22, 2020
7a24f70
fix indentation, remove tostring not needed
Yiyiyimu Aug 23, 2020
091dbbf
catch etcd_version_from_cmd failure
Yiyiyimu Aug 26, 2020
4b4d100
make function name readable
Yiyiyimu Aug 26, 2020
b9c5dc3
bugfix: create etcd instance in `timer`, `cosocket` is not valid in `…
membphis Aug 30, 2020
58d98ee
bugfix: create `etcd_cli` object if it is not autorun model.
membphis Aug 30, 2020
781e92a
remove init_etcd, since watch not need create dir first
Yiyiyimu Sep 3, 2020
c2e02e7
Merge branch 'master' of https://github.com/apache/incubator-apisix i…
Yiyiyimu Sep 3, 2020
b4955ea
update etcd to v3.4, for auth correctly working
Yiyiyimu Sep 3, 2020
73c96c8
fix typo
Yiyiyimu Sep 3, 2020
95aba51
move etcd & etcdctl to default path
Yiyiyimu Sep 3, 2020
af6b7f8
fix typo
Yiyiyimu Sep 3, 2020
f938505
init prev_index to 0
Yiyiyimu Sep 3, 2020
661d9a9
readd init_etcd for now, due to effect logic in config_etcd a lot
Yiyiyimu Sep 4, 2020
bd49c6b
fix typo
Yiyiyimu Sep 4, 2020
92bba2f
remove basexx lib
Yiyiyimu Sep 4, 2020
74cd62f
fix lint
Yiyiyimu Sep 4, 2020
03ce792
fix typo
Yiyiyimu Sep 4, 2020
df89d8d
rm init_etcd
Yiyiyimu Sep 4, 2020
0902ff2
fix typo
Yiyiyimu Sep 4, 2020
f20697c
Merge branch 'master' of https://github.com/apache/incubator-apisix i…
Yiyiyimu Sep 8, 2020
f5eb657
Merge branch 'master' of https://github.com/apache/incubator-apisix i…
Yiyiyimu Sep 10, 2020
401c770
init_etcd back, with a tiny base64 lib
Yiyiyimu Sep 10, 2020
5a3ea6b
revert
johzchen Sep 10, 2020
1fe1f22
optimize waitdir
Yiyiyimu Sep 10, 2020
4949580
Merge branch 'simple-etcdv3' of https://github.com/yiyiyimu/incubator…
Yiyiyimu Sep 10, 2020
85e2e0b
Merge branch 'master' of https://github.com/apache/incubator-apisix i…
Yiyiyimu Sep 10, 2020
78da2dd
[WIP]etcd test
Yiyiyimu Sep 10, 2020
0a4dbd2
[WIP]etcd test
Yiyiyimu Sep 10, 2020
9d7d7fe
fix lint
Yiyiyimu Sep 11, 2020
4ea856b
test: delete if needed
Yiyiyimu Sep 11, 2020
091f97b
revert
Yiyiyimu Sep 11, 2020
fbd200c
fix lint
Yiyiyimu Sep 12, 2020
203c3e3
update test cases
johzchen Sep 12, 2020
b0ca069
fix err
johzchen Sep 12, 2020
a4d92bd
delete test case first
johzchen Sep 12, 2020
18ec078
fix: err
johzchen Sep 12, 2020
34ccfbb
try twice watch to skip create info
johzchen Sep 12, 2020
9735d25
fix: lint
johzchen Sep 14, 2020
5f9b586
Merge branch 'master' into simple-etcdv3
moonming Sep 14, 2020
075eb7f
install etcd in a shell script
johzchen Sep 14, 2020
099a86b
fix code style
johzchen Sep 14, 2020
a85203c
add doc
Sep 14, 2020
4edd3a0
add doc
Yiyiyimu Sep 14, 2020
b400194
test: remove the 1999 port listening and reuse 1980~1982.
membphis Sep 15, 2020
13c276e
Merge branch 'master' into simple-etcdv3
moonming Sep 15, 2020
59a59fd
merge
Yiyiyimu Sep 15, 2020
d2e3d01
rm not reached conditions
Yiyiyimu Sep 15, 2020
58e8401
check if etcd above v3.4
Yiyiyimu Sep 15, 2020
3688862
optimize output of etcd version check
Yiyiyimu Sep 15, 2020
fc93f3d
fix typo
Yiyiyimu Sep 15, 2020
ca7324d
compatibility for etcd version
Yiyiyimu Sep 15, 2020
7e33e71
use check_or_version for comparison
Yiyiyimu Sep 15, 2020
c990fe3
update func name
Yiyiyimu Sep 15, 2020
0570fdb
fix: etcd needed version
johzchen Sep 15, 2020
7d30618
Merge branch 'master' into simple-etcdv3
Yiyiyimu Sep 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis/linux_apisix_current_luarocks_runner.sh
Expand Up @@ -51,6 +51,7 @@ script() {
mkdir -p ~/etcd-data
/usr/bin/etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls='http://0.0.0.0:2379' --data-dir ~/etcd-data > /dev/null 2>&1 &
etcd --version
export ETCDCTL_API=3
Yiyiyimu marked this conversation as resolved.
Show resolved Hide resolved
sleep 5

sudo rm -rf /usr/local/apisix
Expand Down
1 change: 1 addition & 0 deletions .travis/linux_apisix_master_luarocks_runner.sh
Expand Up @@ -51,6 +51,7 @@ script() {
mkdir -p ~/etcd-data
/usr/bin/etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls='http://0.0.0.0:2379' --data-dir ~/etcd-data > /dev/null 2>&1 &
etcd --version
export ETCDCTL_API=3
sleep 5

sudo rm -rf /usr/local/apisix
Expand Down
1 change: 1 addition & 0 deletions .travis/linux_openresty_mtls_runner.sh
Expand Up @@ -95,6 +95,7 @@ script() {
mkdir -p ~/etcd-data
/usr/bin/etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls='http://0.0.0.0:2379' --data-dir ~/etcd-data > /dev/null 2>&1 &
etcd --version
export ETCDCTL_API=3
Yiyiyimu marked this conversation as resolved.
Show resolved Hide resolved
sleep 5


Expand Down
1 change: 1 addition & 0 deletions .travis/linux_openresty_runner.sh
Expand Up @@ -132,6 +132,7 @@ script() {
mkdir -p ~/etcd-data
/usr/bin/etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls='http://0.0.0.0:2379' --data-dir ~/etcd-data > /dev/null 2>&1 &
etcd --version
export ETCDCTL_API=3
sleep 5

./build-cache/grpc_server_example &
Expand Down
2 changes: 2 additions & 0 deletions .travis/linux_tengine_runner.sh
Expand Up @@ -245,6 +245,7 @@ do_install() {
rm -rf luarocks-2.4.4

export GO111MOUDULE=on
export ETCDCTL_API=3

if [ ! -f "build-cache/apisix-master-0.rockspec" ]; then
create_lua_deps
Expand Down Expand Up @@ -285,6 +286,7 @@ script() {
mkdir -p ~/etcd-data
/usr/bin/etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls='http://0.0.0.0:2379' --data-dir ~/etcd-data > /dev/null 2>&1 &
etcd --version
export ETCDCTL_API=3
sleep 5

./build-cache/grpc_server_example &
Expand Down
1 change: 1 addition & 0 deletions .travis/osx_openresty_runner.sh
Expand Up @@ -66,6 +66,7 @@ script() {

export_or_prefix
export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$OPENRESTY_PREFIX/bin:$PATH
export ETCDCTL_API=3

etcd --enable-v2=true &
sleep 1
Expand Down
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -72,6 +72,7 @@ lint: utils
### init: Initialize the runtime environment
.PHONY: init
init: default
export ETCDCTL_API=3
./bin/apisix init
./bin/apisix init_etcd

Expand Down
4 changes: 3 additions & 1 deletion apisix/core.lua
Expand Up @@ -19,7 +19,9 @@ local local_conf = require("apisix.core.config_local").local_conf()

local config_center = local_conf.apisix and local_conf.apisix.config_center
or "etcd"
local etcd_version = local_conf.etcd.version == "v3" and "_v3" or ""
Yiyiyimu marked this conversation as resolved.
Show resolved Hide resolved
log.info("use config_center: ", config_center)
log.info("etcd version: ", etcd_version)

return {
version = require("apisix.core.version"),
Expand All @@ -35,7 +37,7 @@ return {
timer = require("apisix.core.timer"),
id = require("apisix.core.id"),
utils = require("apisix.core.utils"),
etcd = require("apisix.core.etcd"),
etcd = require("apisix.core.etcd" .. etcd_version),
http = require("apisix.core.http"),
tablepool= require("tablepool"),
empty_tab= {},
Expand Down
45 changes: 42 additions & 3 deletions apisix/core/config_etcd.lua
Expand Up @@ -17,6 +17,7 @@
local config_local = require("apisix.core.config_local")
local log = require("apisix.core.log")
local json = require("apisix.core.json")
local etcd_v3 = require("apisix.core.etcd_v3")
local etcd = require("resty.etcd")
local new_tab = require("table.new")
local clone_tab = require("table.clone")
Expand Down Expand Up @@ -48,14 +49,15 @@ local mt = {
return " etcd key: " .. self.key
end
}
local etcd_version = _M.local_conf().etcd.version or "v2"
Yiyiyimu marked this conversation as resolved.
Show resolved Hide resolved


local function getkey(etcd_cli, key)
if not etcd_cli then
return nil, "not inited"
end

local res, err = etcd_cli:get(key)
local res, err = etcd_cli:readdir(key)
if not res then
-- log.error("failed to get key from etcd: ", err)
return nil, err
Expand All @@ -65,6 +67,13 @@ local function getkey(etcd_cli, key)
return nil, "failed to get key from etcd"
end

if(etcd_version == "v3") then
res, err = etcd_v3.postget(res, key)
if not res then
return nil, err
end
end

return res
end

Expand All @@ -74,7 +83,7 @@ local function readdir(etcd_cli, key)
return nil, nil, "not inited"
end

local res, err = etcd_cli:readdir(key, true)
local res, err = etcd_cli:readdir(key)
if not res then
-- log.error("failed to get key from etcd: ", err)
return nil, nil, err
Expand All @@ -84,6 +93,13 @@ local function readdir(etcd_cli, key)
return nil, "failed to read etcd dir"
end

if(etcd_version == "v3") then
res, err = etcd_v3.postget(res, key .. "/")
if not res then
return nil, err
end
end

return res
end

Expand All @@ -92,12 +108,33 @@ local function waitdir(etcd_cli, key, modified_index, timeout)
return nil, nil, "not inited"
end

local res, err = etcd_cli:waitdir(key, modified_index, timeout)
local res, err
if etcd_version == "v3" then
local opts = {}
opts.start_revision = modified_index
opts.timeout = timeout
local res_fun, fun_err = etcd_cli:watchdir(key, opts)
if not res_fun then
return nil, fun_err
end
res_fun() -- skip create info
res, err = res_fun()
else
res, err = etcd_cli:waitdir(key, modified_index, timeout)
end

if not res then
-- log.error("failed to get key from etcd: ", err)
return nil, err
end

if etcd_version == "v3" then
if type(res.result) ~= "table" then
return nil, "failed to read etcd dir"
end
return etcd_v3.postwatch(res)
end

if type(res.body) ~= "table" then
return nil, "failed to read etcd dir"
end
Expand Down Expand Up @@ -430,6 +467,8 @@ function _M.new(key, opts)
etcd_conf.http_host = etcd_conf.host
etcd_conf.host = nil
etcd_conf.prefix = nil
etcd_conf.protocol = etcd_conf.version
etcd_conf.version = nil

local etcd_cli
etcd_cli, err = etcd.new(etcd_conf)
Expand Down