Skip to content

fix: kubenetes dump data empty when kubenetes discover service in min… #11919

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions apisix/discovery/kubernetes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -619,21 +619,20 @@ 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 discovery_conf = local_conf.discovery.kubernetes
if #discovery_conf == 0 then
local endpoint_dict = get_endpoint_dict()
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
if key:sub(-#"#version") ~= "#version" then
local value = endpoint_dict:get(key)
Expand All @@ -646,11 +645,45 @@ function _M.dump_data()
end

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

end
else
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
if key:sub(-#"#version") ~= "#version" then
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
end

return {config = local_conf.discovery.kubernetes, endpoints = eps}
Expand Down
Loading