Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add discovery k8s dump data interface #11111

Merged
merged 13 commits into from
Apr 18, 2024
42 changes: 42 additions & 0 deletions apisix/discovery/kubernetes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -615,4 +615,46 @@ function _M.init_worker()
end
end


function _M.dump_data()

local eps = {}
for _, conf in ipairs(local_conf.discovery.kubernetes) do

local id = conf.id
local endpoint_dict = get_endpoint_dict(id)
local keys, err = endpoint_dict:get_keys()
if err then
error(err)
break
end

if keys then
local k8s = {}
for i = 1, #keys do

local key = keys[i]
--skip key with suffix #version
shreemaan-abhishek marked this conversation as resolved.
Show resolved Hide resolved
if key:sub(-#"#version") ~= "#version" then
shreemaan-abhishek marked this conversation as resolved.
Show resolved Hide resolved
local value = endpoint_dict:get(key)

core.table.insert(k8s, {
name = key,
value = value
})
end
end

core.table.insert(eps, {
id = conf.id,
endpoints = k8s
})

end
end

return {config = local_conf.discovery.kubernetes, endpoints = eps}
end


return _M
9 changes: 9 additions & 0 deletions t/kubernetes/discovery/kubernetes3.t
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ _EOC_
core.log.err("operator k8s cluster error: ", err)
return 500
end

ngx.sleep(1)

local k8s = require("apisix.discovery.kubernetes")
local data = k8s.dump_data()
ngx.say(core.json.encode(data,true))

hanqingwu marked this conversation as resolved.
Show resolved Hide resolved
if res.status ~= 200 and res.status ~= 201 and res.status ~= 409 then
return res.status
end
Expand Down Expand Up @@ -332,6 +339,8 @@ POST /operators
]
--- more_headers
Content-type: application/json
--- response_body_like
.*"endpoints".*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- response_body_like
.*"endpoints".*

this doesn't seem sufficient to show that the feature works fine. The verification should be more descriptive.




Expand Down
Loading