Skip to content

Commit

Permalink
feat(clustering/rpc): add dp labels support (#14046)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored Dec 24, 2024
1 parent c77a178 commit 8e14a18
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
17 changes: 17 additions & 0 deletions kong/clustering/rpc/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ function _M:_handle_meta_call(c)
local capabilities_list = info.rpc_capabilities
local node_id = info.kong_node_id

-- we already set this dp node
if self.client_capabilities[node_id] then
return node_id
end

self.client_capabilities[node_id] = {
set = pl_tablex_makeset(capabilities_list),
list = capabilities_list,
Expand All @@ -210,10 +215,22 @@ function _M:_handle_meta_call(c)
assert(self.concentrator)
assert(self.client_info)

-- see communicate() in data_plane.lua
local labels do
if info.kong_conf.cluster_dp_labels then
labels = {}
for _, lab in ipairs(info.kong_conf.cluster_dp_labels) do
local del = lab:find(":", 1, true)
labels[lab:sub(1, del - 1)] = lab:sub(del + 1)
end
end
end

-- store DP's ip addr
self.client_info[node_id] = {
ip = ngx_var.remote_addr,
version = info.kong_version,
labels = labels,
}

return node_id
Expand Down
1 change: 1 addition & 0 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function _M:init_cp(manager)
hostname = node_id,
ip = node_info.ip, -- get the correct ip
version = node_info.version, -- get from rpc call
labels = node_info.labels, -- get from rpc call
sync_status = CLUSTERING_SYNC_STATUS.NORMAL,
config_hash = fmt("%032d", default_namespace_version),
rpc_capabilities = rpc_peers and rpc_peers[node_id] or {},
Expand Down
8 changes: 2 additions & 6 deletions spec/02-integration/09-hybrid_mode/01-sync_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -801,12 +801,8 @@ describe("CP/DP labels #" .. strategy, function()
assert.matches("^(%d+%.%d+)%.%d+", v.version)
assert.equal(CLUSTERING_SYNC_STATUS.NORMAL, v.sync_status)
assert.equal(CLUSTERING_SYNC_STATUS.NORMAL, v.sync_status)
-- TODO: The API output does include labels and certs when the
-- rpc sync is enabled.
if rpc_sync == "off" then
assert.equal("mycloud", v.labels.deployment)
assert.equal("us-east-1", v.labels.region)
end
assert.equal("mycloud", v.labels.deployment)
assert.equal("us-east-1", v.labels.region)
return true
end
end
Expand Down

1 comment on commit 8e14a18

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Bazel Build

Docker image available kong/kong:8e14a18c4d56bd726833ecf305c56fbf209ed943
Artifacts available https://github.com/Kong/kong/actions/runs/12479949473

Please sign in to comment.