diff --git a/kong/clustering/rpc/manager.lua b/kong/clustering/rpc/manager.lua index c90bbb56b69b..142c90a194c7 100644 --- a/kong/clustering/rpc/manager.lua +++ b/kong/clustering/rpc/manager.lua @@ -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, @@ -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 diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index b6525c3ee04a..e19960a45eec 100644 --- a/kong/clustering/services/sync/rpc.lua +++ b/kong/clustering/services/sync/rpc.lua @@ -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 {}, diff --git a/spec/02-integration/09-hybrid_mode/01-sync_spec.lua b/spec/02-integration/09-hybrid_mode/01-sync_spec.lua index 4877869c4a23..9eea5ed30fb3 100644 --- a/spec/02-integration/09-hybrid_mode/01-sync_spec.lua +++ b/spec/02-integration/09-hybrid_mode/01-sync_spec.lua @@ -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