tokers commented on a change in pull request #2233:
URL: https://github.com/apache/apisix/pull/2233#discussion_r489186316



##########
File path: bin/apisix
##########
@@ -885,20 +939,44 @@ local function init_etcd(show_output)
         yaml_conf.etcd.host = {yaml_conf.etcd.host}
     end
 
+    local cluster_version
     local host_count = #(yaml_conf.etcd.host)
-
-    local etcd_ok = false
+    -- check the etcd cluster version
     for index, host in ipairs(yaml_conf.etcd.host) do
-        -- check if etcd version above 3.4
-        cmd = "curl " .. host .. "/version 2>&1"
-        local res = excute_cmd(cmd)
-        local op_ver = str_split(res, "\"")[4]
-        local need_ver = "3.4.0"
-        if not check_version(op_ver, need_ver) then
-            io.stderr:write("etcd version must >=", need_ver, " current ", 
op_ver, "\n")
+        uri = host .. "/version"
+        local cmd = string.format("curl -s -m %d %s | sed -e 's/[{}]/''/g'", 
timeout * 2, uri)
+        local res = execute_cmd(cmd)
+        local m = split(res, [[%s*,%s*]])
+        local errmsg = string.format("got malformed version message: \"%s\" 
from etcd", res)
+
+        for i = 1, #m do
+            local mm = split(m[i], [[%s*:%s*]])
+            if #mm ~= 2 then
+                io.stderr:write(errmsg)
+                return
+            end
+
+            if mm[1] == "\"etcdcluster\"" then
+                cluster_version = string.sub(mm[2], 2, -2)
+                break
+            end
+        end
+
+        if not cluster_version then
+            io.stderr:write(errmsg)
             return
         end
 
+        if compare_semantic_version(cluster_version, min_etcd_version) then
+            io.stderr:write(string.format("etcd cluster version \"%s\" is less 
than the required version \"%s\", please upgrade your etcd cluster", 
cluster_version, min_etcd_version))

Review comment:
       OK, will split this line.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to