Yiyiyimu commented on a change in pull request #2036:
URL: https://github.com/apache/apisix/pull/2036#discussion_r475051880
##########
File path: bin/apisix
##########
@@ -870,35 +870,30 @@ local function init_etcd(show_output)
local host_count = #(yaml_conf.etcd.host)
- -- check whether the user has enabled etcd v2 protocol
- for index, host in ipairs(yaml_conf.etcd.host) do
- uri = host .. "/v2/keys"
- local cmd = "curl -i -m ".. timeout * 2 .. " -o /dev/null -s -w
%{http_code} " .. uri
- local res = excute_cmd(cmd)
- if res == "404" then
- io.stderr:write(string.format("failed: please make sure that you
have enabled the v2 protocol of etcd on %s.\n", host))
- return
- end
- end
-
local etcd_ok = false
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
- .. "?prev_exist=false -X PUT -d dir=true "
- .. "--connect-timeout " .. timeout
- .. " --max-time " .. timeout * 2 .. " --retry 1 2>&1"
+ local res = require("posix.stdlib").setenv("ETCDCTL_API", 3)
+ local key = (etcd_conf.prefix or "") .. dir_name .. "/"
+ -- use suggested v3 ctl `etcdctl` and avoid base64 conversion
+ --local base64 = require("base64")
+ --uri = host .. "/v3/kv/put"
+ --local post_json = '{"value":"' .. base64.encode("null") .. '",
"key":"' .. base64.encode(key) .. '"}'
+ --cmd = "curl " .. uri
+ -- .. " -X POST -d '" .. post_json
+ -- .. "' --connect-timeout " .. timeout
+ -- .. " --max-time " .. timeout * 2 .. " --retry 1 2>&1"
+ local cmd = "etcdctl --endpoints=" .. host .. " put " .. key .. "
init_dir"
Review comment:
etcd v3 is not suggested to use `curl` to call etcd API due to we need
to transmit base64 encoded key and value, and base64 library is somehow broken
here.
Thus I turned to use suggested `etcdctl` to do the same thing, but in this
case, we could not set `connect-timeout` and `max-time` anymore, does that
matter?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]