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

Add multiple etcd support. #1283

Merged
merged 5 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions bin/apisix
Original file line number Diff line number Diff line change
Expand Up @@ -706,28 +706,48 @@ local function init_etcd(show_output)
end

local etcd_conf = yaml_conf.etcd
local uri = etcd_conf.host .. "/v2/keys" .. (etcd_conf.prefix or "")

local timeout = etcd_conf.timeout or 3
local uri
--convert old single etcd config to multiple etcd config
if type(yaml_conf.etcd.host) == "string" then
yaml_conf.etcd.host = {yaml_conf.etcd.host}
end

Akayeshmantha marked this conversation as resolved.
Show resolved Hide resolved
local host_count = #(yaml_conf.etcd.host)
Akayeshmantha marked this conversation as resolved.
Show resolved Hide resolved

for index, host in ipairs(yaml_conf.etcd.host) do

local is_success = true
uri = host .. "/v2/keys" .. (etcd_conf.prefix or "")

for _, dir_name in ipairs({"/routes", "/upstreams", "/services",
"/plugins", "/consumers", "/node_status",
"/ssl", "/global_rules", "/stream_routes",
"/proto"}) do
local cmd = "curl " .. uri .. dir_name
for _, dir_name in ipairs({"/routes", "/upstreams", "/services",
Akayeshmantha marked this conversation as resolved.
Show resolved Hide resolved
"/plugins", "/consumers", "/node_status",
"/ssl", "/global_rules", "/stream_routes",
"/proto"}) do
local cmd = "curl " .. uri .. dir_name
.. "?prev_exist=false -X PUT -d dir=true "
.. "--connect-timeout " .. timeout
.. " --max-time " .. timeout * 2 .. " --retry 1 2>&1"

local res = exec(cmd)
if not res:find("index", 1, true)
and not res:find("createdIndex", 1, true) then
error(cmd .. "\n" .. res)
local res = exec(cmd)
if not res:find("index", 1, true)
and not res:find("createdIndex", 1, true) then
is_success = false
if (index == hostCount) then
error(cmd .. "\n" .. res)
end
break
end

if show_output then
print(cmd)
print(res)
end
end

if show_output then
print(cmd)
print(res)
if is_success then
break
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ nginx_config: # config for render the template to genarate n
- 'unix:'

etcd:
host: "http://127.0.0.1:2379" # etcd address
host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
- "http://127.0.0.1:2379" # multiple etcd address
prefix: "/apisix" # apisix configurations prefix
timeout: 3 # 3 seconds

Expand Down