membphis commented on a change in pull request #2036: URL: https://github.com/apache/apisix/pull/2036#discussion_r475192884
########## File path: apisix/core/config_etcd.lua ########## @@ -268,86 +289,90 @@ local function sync_data(self) return false, err end - local key = short_key(self, res.key) - if res.value and type(res.value) ~= "table" then - self:upgrade_version(res.modifiedIndex) - return false, "invalid item data of [" .. self.key .. "/" .. key - .. "], val: " .. tostring(res.value) - .. ", it shoud be a object" - end - - if res.value and self.item_schema then - local ok, err = check_schema(self.item_schema, res.value) - if not ok then + local res_copy = res + for _, res in ipairs(res_copy) do + local key = short_key(self, res.key) + if res.value and type(res.value) ~= "table" then self:upgrade_version(res.modifiedIndex) - - return false, "failed to check item data of [" - .. self.key .. "] err:" .. err + return false, "invalid item data of [" .. self.key .. "/" .. key + .. "], val: " .. tostring(res.value) Review comment: bad indentation ########## File path: rockspec/apisix-master-0.rockspec ########## @@ -52,6 +52,7 @@ dependencies = { "lua-resty-kafka = 0.07", "lua-resty-logger-socket = 2.0-0", "skywalking-nginx-lua-plugin = 1.0-0", + "luaposix = 35.0-1", Review comment: why we need this Lua module? ########## 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 Review comment: only one way is easier for user. `etcdctl` is enough. ########## File path: apisix/core/config_etcd.lua ########## @@ -268,86 +289,90 @@ local function sync_data(self) return false, err end - local key = short_key(self, res.key) - if res.value and type(res.value) ~= "table" then - self:upgrade_version(res.modifiedIndex) - return false, "invalid item data of [" .. self.key .. "/" .. key - .. "], val: " .. tostring(res.value) - .. ", it shoud be a object" - end - - if res.value and self.item_schema then - local ok, err = check_schema(self.item_schema, res.value) - if not ok then + local res_copy = res + for _, res in ipairs(res_copy) do + local key = short_key(self, res.key) + if res.value and type(res.value) ~= "table" then self:upgrade_version(res.modifiedIndex) - - return false, "failed to check item data of [" - .. self.key .. "] err:" .. err + return false, "invalid item data of [" .. self.key .. "/" .. key + .. "], val: " .. tostring(res.value) Review comment: if the `res.value` is a talbe, we need to encode it with `json` if the `res.value` is non-table, we do not need to call `tostring` ---------------------------------------------------------------- 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