Skip to content

Commit

Permalink
chore(clustering): do not enable kong.sync.v2 when connecting dp is o…
Browse files Browse the repository at this point in the history
…lder than cp

Signed-off-by: Aapo Talvensaari <[email protected]>
  • Loading branch information
bungle committed Jan 24, 2025
1 parent 7a505ea commit acec33e
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions kong/clustering/rpc/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ local callbacks = require("kong.clustering.rpc.callbacks")
local clustering_tls = require("kong.clustering.tls")
local constants = require("kong.constants")
local table_isempty = require("table.isempty")
local pl_tablex = require("pl.tablex")
local table_clone = require("table.clone")
local table_remove = table.remove
local cjson = require("cjson.safe")
local string_tools = require("kong.tools.string")

Expand All @@ -25,7 +26,7 @@ local ngx_log = ngx.log
local ngx_exit = ngx.exit
local ngx_time = ngx.time
local exiting = ngx.worker.exiting
local pl_tablex_makeset = pl_tablex.makeset
local pl_tablex_makeset = require("pl.tablex").makeset
local cjson_encode = cjson.encode
local cjson_decode = cjson.decode
local validate_client_cert = clustering_tls.validate_client_cert
Expand Down Expand Up @@ -188,10 +189,34 @@ function _M:_handle_meta_call(c, cert)
assert(type(info.kong_hostname) == "string")
assert(type(info.kong_conf) == "table")

local version = info.kong_version
local rpc_capabilities = self.callbacks:get_capabilities_list(version)
-- For data planes older than the control plane, we don't want to enable
-- kong.sync.v2 because we decided to not add the compatibility layer to
-- it. The v1 sync implements the compatibility code, and thus by not
-- adverticing the kong.sync.v2 the data plane will automatically fall
-- back to v1 sync.
--
-- In case we want to reverse the decision, the compatibility code for the
-- kong.sync.v2 can be found here: https://github.com/Kong/kong-ee/pull/11040
if KONG_VERSION > version then
local delta_index
for i, rpc_capability in ipairs(rpc_capabilities) do
if rpc_capability == "kong.sync.v2" then
delta_index = i
break
end
end
if delta_index then
rpc_capabilities = table_clone(rpc_capabilities)
table_remove(rpc_capabilities, delta_index)
end
end

local payload = {
jsonrpc = jsonrpc.VERSION,
result = {
rpc_capabilities = self.callbacks:get_capabilities_list(),
rpc_capabilities = rpc_capabilities,
-- now we only support snappy
rpc_frame_encoding = RPC_SNAPPY_FRAMED,
},
Expand Down Expand Up @@ -239,7 +264,7 @@ function _M:_handle_meta_call(c, cert)
-- store DP's ip addr
self.client_info[node_id] = {
ip = ngx_var.remote_addr,
version = info.kong_version,
version = version,
labels = labels,
cert_details = cert_details,
}
Expand Down

0 comments on commit acec33e

Please sign in to comment.