From d387e749b6fb988172e9a4b16a837253b1e076fd Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Thu, 7 Nov 2024 10:15:36 -0800 Subject: [PATCH] chore: refactor wasm crud event-handler --- kong/runloop/events.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/kong/runloop/events.lua b/kong/runloop/events.lua index d3b88fff1e4a..ab982cf1fae2 100644 --- a/kong/runloop/events.lua +++ b/kong/runloop/events.lua @@ -312,23 +312,25 @@ local function crud_wasm_handler(data, schema_name) return end + local updated = false + + -- always invalidate for filter_chain entity changes + if schema_name == "filter_chains" then + updated = true + -- cache is invalidated on service/route deletion to ensure we don't -- have oprhaned filter chain data cached - local is_delete = data.operation == "delete" - and (schema_name == "services" - or schema_name == "routes") + elseif schema_name == "services" or schema_name == "routes" + updated = data.operation == "delete" - local is_filter_plugin = false - if schema_name == "plugins" then + -- invalidate for changes to wasm filter plugin entities + elseif schema_name == "plugins" then local new_name = data.entity.name local old_name = data.old_entity and data.old_entity.name - is_filter_plugin = (new_name and wasm.filters_by_name[new_name]) or - (old_name and wasm.filters_by_name[old_name]) + updated = (new_name and wasm.filters_by_name[new_name]) or + (old_name and wasm.filters_by_name[old_name]) end - local updated = schema_name == "filter_chains" or is_delete or is_filter_plugin - - if updated then log(DEBUG, "[events] wasm filter chains updated, invalidating cache") core_cache:invalidate("filter_chains:version")