Skip to content

Commit 8e14a18

Browse files
authored
feat(clustering/rpc): add dp labels support (#14046)
KAG-5973, KAG-5935
1 parent c77a178 commit 8e14a18

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

kong/clustering/rpc/manager.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ function _M:_handle_meta_call(c)
201201
local capabilities_list = info.rpc_capabilities
202202
local node_id = info.kong_node_id
203203

204+
-- we already set this dp node
205+
if self.client_capabilities[node_id] then
206+
return node_id
207+
end
208+
204209
self.client_capabilities[node_id] = {
205210
set = pl_tablex_makeset(capabilities_list),
206211
list = capabilities_list,
@@ -210,10 +215,22 @@ function _M:_handle_meta_call(c)
210215
assert(self.concentrator)
211216
assert(self.client_info)
212217

218+
-- see communicate() in data_plane.lua
219+
local labels do
220+
if info.kong_conf.cluster_dp_labels then
221+
labels = {}
222+
for _, lab in ipairs(info.kong_conf.cluster_dp_labels) do
223+
local del = lab:find(":", 1, true)
224+
labels[lab:sub(1, del - 1)] = lab:sub(del + 1)
225+
end
226+
end
227+
end
228+
213229
-- store DP's ip addr
214230
self.client_info[node_id] = {
215231
ip = ngx_var.remote_addr,
216232
version = info.kong_version,
233+
labels = labels,
217234
}
218235

219236
return node_id

kong/clustering/services/sync/rpc.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ function _M:init_cp(manager)
8585
hostname = node_id,
8686
ip = node_info.ip, -- get the correct ip
8787
version = node_info.version, -- get from rpc call
88+
labels = node_info.labels, -- get from rpc call
8889
sync_status = CLUSTERING_SYNC_STATUS.NORMAL,
8990
config_hash = fmt("%032d", default_namespace_version),
9091
rpc_capabilities = rpc_peers and rpc_peers[node_id] or {},

spec/02-integration/09-hybrid_mode/01-sync_spec.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,8 @@ describe("CP/DP labels #" .. strategy, function()
801801
assert.matches("^(%d+%.%d+)%.%d+", v.version)
802802
assert.equal(CLUSTERING_SYNC_STATUS.NORMAL, v.sync_status)
803803
assert.equal(CLUSTERING_SYNC_STATUS.NORMAL, v.sync_status)
804-
-- TODO: The API output does include labels and certs when the
805-
-- rpc sync is enabled.
806-
if rpc_sync == "off" then
807-
assert.equal("mycloud", v.labels.deployment)
808-
assert.equal("us-east-1", v.labels.region)
809-
end
804+
assert.equal("mycloud", v.labels.deployment)
805+
assert.equal("us-east-1", v.labels.region)
810806
return true
811807
end
812808
end

0 commit comments

Comments
 (0)