From 1d100009df392d268cee2c35ba96b171c3e54245 Mon Sep 17 00:00:00 2001 From: xumin Date: Wed, 30 Oct 2024 15:23:09 +0800 Subject: [PATCH] fix(clustering): avoid 500 accessing v1 api when inc_sync enabled fix KAG-5551 --- kong/init.lua | 20 +++++++++---------- .../09-hybrid_mode/01-sync_spec.lua | 17 +++++++++------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/kong/init.lua b/kong/init.lua index 81b5d2c3817c..0b6493464957 100644 --- a/kong/init.lua +++ b/kong/init.lua @@ -884,12 +884,18 @@ function Kong.init_worker() kong.cache:invalidate_local(constants.ADMIN_GUI_KCONFIG_CACHE_KEY) end - if process.type() == "privileged agent" and not kong.sync then - if kong.clustering then - -- full sync cp/dp + if kong.clustering then + -- full sync dp + -- "privileged agent" must be a DP worker + if process.type() == "privileged agent" and not kong.sync then + kong.clustering:init_worker() + -- DP privileged agent skips the rest of the init_worker + return + + elseif is_control_plane(kong.configuration) then + -- CP needs to support both full and incremental sync kong.clustering:init_worker() end - return end kong.vault.init_worker() @@ -987,12 +993,6 @@ function Kong.init_worker() end if kong.clustering then - - -- full sync cp/dp - if not kong.sync then - kong.clustering:init_worker() - end - -- rpc and incremental sync if kong.rpc and is_http_module then 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 a1d2f9b37641..ad8b8928ae65 100644 --- a/spec/02-integration/09-hybrid_mode/01-sync_spec.lua +++ b/spec/02-integration/09-hybrid_mode/01-sync_spec.lua @@ -12,8 +12,7 @@ local uuid = require("kong.tools.uuid").uuid local KEY_AUTH_PLUGIN ---- XXX FIXME: enable inc_sync = on -for _, inc_sync in ipairs { "off" } do +for _, inc_sync in ipairs { "on", "off" } do for _, strategy in helpers.each_strategy() do describe("CP/DP communication #" .. strategy .. " inc_sync=" .. inc_sync, function() @@ -624,7 +623,11 @@ describe("CP/DP #version check #" .. strategy, function() end) end) -describe("CP/DP config sync #" .. strategy, function() +--- XXX FIXME: enable inc_sync = on +-- skips the rest of the tests. We will fix them in a follow-up PR +local skip_inc_sync = inc_sync == "on" and pending or describe + +skip_inc_sync("CP/DP config sync #" .. strategy, function() lazy_setup(function() helpers.get_db_utils(strategy) -- runs migrations @@ -656,7 +659,7 @@ describe("CP/DP config sync #" .. strategy, function() end) describe("sync works", function() - it("pushes first change asap and following changes in a batch", function() + it("pushes first change asap and following changes in a batch #t", function() local admin_client = helpers.admin_client(10000) local proxy_client = helpers.http_client("127.0.0.1", 9002) finally(function() @@ -736,7 +739,7 @@ describe("CP/DP config sync #" .. strategy, function() end) end) -describe("CP/DP labels #" .. strategy, function() +skip_inc_sync("CP/DP labels #" .. strategy, function() lazy_setup(function() helpers.get_db_utils(strategy) -- runs migrations @@ -799,7 +802,7 @@ describe("CP/DP labels #" .. strategy, function() end) end) -describe("CP/DP cert details(cluster_mtls = shared) #" .. strategy, function() +skip_inc_sync("CP/DP cert details(cluster_mtls = shared) #" .. strategy, function() lazy_setup(function() helpers.get_db_utils(strategy) -- runs migrations @@ -856,7 +859,7 @@ describe("CP/DP cert details(cluster_mtls = shared) #" .. strategy, function() end) end) -describe("CP/DP cert details(cluster_mtls = pki) #" .. strategy, function() +skip_inc_sync("CP/DP cert details(cluster_mtls = pki) #" .. strategy, function() lazy_setup(function() helpers.get_db_utils(strategy) -- runs migrations