You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by al...@apache.org on 2023/11/30 05:09:43 UTC
(apisix) branch fix/admin-list created (now 5b41ae6bf)
This is an automated email from the ASF dual-hosted git repository.
alinsran pushed a change to branch fix/admin-list
in repository https://gitbox.apache.org/repos/asf/apisix.git
at 5b41ae6bf fix: missing etcd init_dir and unable to list resource
This branch includes the following new commits:
new 5b41ae6bf fix: missing etcd init_dir and unable to list resource
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(apisix) 01/01: fix: missing etcd init_dir and unable to list resource
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alinsran pushed a commit to branch fix/admin-list
in repository https://gitbox.apache.org/repos/asf/apisix.git
commit 5b41ae6bfba0f03b3e9ed8af1216a634212f8f8c
Author: AlinsRan <al...@apache.org>
AuthorDate: Wed Nov 29 19:55:56 2023 +0800
fix: missing etcd init_dir and unable to list resource
---
apisix/core/etcd.lua | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/apisix/core/etcd.lua b/apisix/core/etcd.lua
index 5cd103858..207a89dee 100644
--- a/apisix/core/etcd.lua
+++ b/apisix/core/etcd.lua
@@ -32,6 +32,7 @@ local setmetatable = setmetatable
local string = string
local tonumber = tonumber
local ngx_get_phase = ngx.get_phase
+--local inspect = require "inspect"
local _M = {}
@@ -154,16 +155,6 @@ local function kvs_to_node(kvs)
end
_M.kvs_to_node = kvs_to_node
-local function kvs_to_nodes(res)
- res.body.node.dir = true
- res.body.node.nodes = setmetatable({}, array_mt)
- for i=2, #res.body.kvs do
- res.body.node.nodes[i-1] = kvs_to_node(res.body.kvs[i])
- end
- return res
-end
-
-
local function not_found(res)
res.body.message = "Key not found"
res.reason = "Not found"
@@ -211,18 +202,27 @@ function _M.get_format(res, real_key, is_dir, formatter)
else
-- In etcd v2, the direct key asked for is `node`, others which under this dir are `nodes`
-- While in v3, this structure is flatten and all keys related the key asked for are `kvs`
- res.body.node = kvs_to_node(res.body.kvs[1])
+ res.body.node = {}
+ res.body.node.dir = true
+ res.body.node.nodes = setmetatable({}, array_mt)
if not res.body.kvs[1].value then
- -- remove last "/" when necessary
- if string.byte(res.body.node.key, -1) == 47 then
- res.body.node.key = string.sub(res.body.node.key, 1, #res.body.node.key-1)
+ res.body.node.key = real_key
+ for i=2, #res.body.kvs do
+ res.body.node.nodes[i-1] = kvs_to_node(res.body.kvs[i])
+ end
+ else
+ res.body.node.key = real_key
+ for i=1, #res.body.kvs do
+ res.body.node.nodes[i] = kvs_to_node(res.body.kvs[i])
end
- res = kvs_to_nodes(res)
end
+
+ --ngx.log(ngx.ERR, "v2 list", inspect(res.body))
end
res.body.kvs = nil
v3_adapter.to_v3_list(res.body)
+ --ngx.log(ngx.ERR, "v3 list", inspect(res.body))
return res
end
@@ -316,7 +316,7 @@ function _M.get(key, is_dir)
if not res then
return nil, err
end
-
+ --ngx.log(ngx.ERR, "etcd get: ", inspect(res))
return _M.get_format(res, key, is_dir)
end