From a0f954b2a341c87e7a104b6ea75820809e95b038 Mon Sep 17 00:00:00 2001 From: Xiaochen Wang Date: Tue, 3 Dec 2024 14:57:02 +0800 Subject: [PATCH] fix(clustering/rpc) support `cluster_use_proxy` option for clustering rpc protocol --- kong/clustering/rpc/manager.lua | 11 +++++++++++ .../09-hybrid_mode/10-forward-proxy_spec.lua | 10 +++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/kong/clustering/rpc/manager.lua b/kong/clustering/rpc/manager.lua index c3925c5073cba..f3e3e51757220 100644 --- a/kong/clustering/rpc/manager.lua +++ b/kong/clustering/rpc/manager.lua @@ -474,6 +474,17 @@ function _M:connect(premature, node_id, host, path, cert, key) local c = assert(client:new(WS_OPTS)) + if self.conf.cluster_use_proxy then + local proxy_opts = parse_proxy_url(self.conf.proxy_server) + opts.proxy_opts = { + wss_proxy = proxy_opts.proxy_url, + wss_proxy_authorization = proxy_opts.proxy_authorization, + } + + ngx_log(ngx_DEBUG, _log_prefix, + "using proxy ", proxy_opts.proxy_url, " to connect control plane") + end + local ok, err = c:connect(uri, opts) if not ok then ngx_log(ngx_ERR, "[rpc] unable to connect to peer: ", err) diff --git a/spec/02-integration/09-hybrid_mode/10-forward-proxy_spec.lua b/spec/02-integration/09-hybrid_mode/10-forward-proxy_spec.lua index a7f11e41059e5..1dc6d2a2449af 100644 --- a/spec/02-integration/09-hybrid_mode/10-forward-proxy_spec.lua +++ b/spec/02-integration/09-hybrid_mode/10-forward-proxy_spec.lua @@ -71,11 +71,13 @@ local proxy_configs = { -- if existing lmdb data is set, the service/route exists and -- test run too fast before the proxy connection is established --- XXX FIXME: enable inc_sync = on -for _, inc_sync in ipairs { "off" } do +for _, v in ipairs({ {"off", "off"}, {"on", "off"}, {"on", "on"}, }) do + local rpc, inc_sync = v[1], v[2] for _, strategy in helpers.each_strategy() do for proxy_desc, proxy_opts in pairs(proxy_configs) do - describe("CP/DP sync through proxy (" .. proxy_desc .. ") works with #" .. strategy .. " inc_sync=" .. inc_sync .. " backend", function() + describe("CP/DP sync through proxy (" .. proxy_desc .. ") works with #" + .. strategy .. " rpc=" .. rpc .. " inc_sync=" .. inc_sync + .. " backend", function() lazy_setup(function() helpers.get_db_utils(strategy) -- runs migrations @@ -87,6 +89,7 @@ for _, strategy in helpers.each_strategy() do db_update_frequency = 0.1, cluster_listen = "127.0.0.1:9005", nginx_conf = "spec/fixtures/custom_nginx.template", + cluster_rpc = rpc, cluster_incremental_sync = inc_sync, })) @@ -108,6 +111,7 @@ for _, strategy in helpers.each_strategy() do proxy_server_ssl_verify = proxy_opts.proxy_server_ssl_verify, lua_ssl_trusted_certificate = proxy_opts.lua_ssl_trusted_certificate, + cluster_rpc = rpc, cluster_incremental_sync = inc_sync, -- this is unused, but required for the template to include a stream {} block