membphis commented on a change in pull request #2036:
URL: https://github.com/apache/apisix/pull/2036#discussion_r477402880
##########
File path: bin/apisix
##########
@@ -870,35 +870,21 @@ 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",
Review comment:
we can remove those `for` code in etcd v3 now, it is useless
##########
File path: apisix/core/etcd.lua
##########
@@ -15,11 +15,38 @@
-- limitations under the License.
--
local fetch_local_conf = require("apisix.core.config_local").local_conf
-local etcd = require("resty.etcd")
-local clone_tab = require("table.clone")
+local etcd = require("resty.etcd")
+local clone_tab = require("table.clone")
+local io = io
+local type = type
+local ipairs = ipairs
+local string = string
+local tonumber = tonumber
local _M = {version = 0.1}
+local prefix_v3 = {
+ ["3.5"] = "/v3",
+ ["3.4"] = "/v3",
+ ["3.3"] = "/v3beta",
+ ["3.2"] = "/v3alpha",
+}
+
+
+-- TODO: Default lua-resty-etcd version auto-detection is broken, so directly
get version from cmd
+-- we don't need to call this so many times, need to save it in some
place
+local function etcd_version_from_cmd()
+ local cmd = "export ETCDCTL_API=3 && etcdctl version"
Review comment:
here is an example code:
https://github.com/api7/lua-resty-etcd/blob/master/lib/resty/etcd.lua#L17
##########
File path: apisix/core/etcd.lua
##########
@@ -15,11 +15,38 @@
-- limitations under the License.
--
local fetch_local_conf = require("apisix.core.config_local").local_conf
-local etcd = require("resty.etcd")
-local clone_tab = require("table.clone")
+local etcd = require("resty.etcd")
+local clone_tab = require("table.clone")
+local io = io
+local type = type
+local ipairs = ipairs
+local string = string
+local tonumber = tonumber
local _M = {version = 0.1}
+local prefix_v3 = {
+ ["3.5"] = "/v3",
+ ["3.4"] = "/v3",
+ ["3.3"] = "/v3beta",
+ ["3.2"] = "/v3alpha",
+}
+
+
+-- TODO: Default lua-resty-etcd version auto-detection is broken, so directly
get version from cmd
+-- we don't need to call this so many times, need to save it in some
place
+local function etcd_version_from_cmd()
+ local cmd = "export ETCDCTL_API=3 && etcdctl version"
Review comment:
If we only fetch the etcd version, we can use `etcd` v2 library, it
should work fine.
----------------------------------------------------------------
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]