diff --git a/kong/clustering/compat/checkers.lua b/kong/clustering/compat/checkers.lua index 2cc89cba3821..5836cc82cc3a 100644 --- a/kong/clustering/compat/checkers.lua +++ b/kong/clustering/compat/checkers.lua @@ -1,5 +1,6 @@ local ipairs = ipairs local type = type +local string_find = string.find local log_warn_message @@ -23,6 +24,53 @@ end local compatible_checkers = { + { 3007000000, --[[ 3.7.0.0 ]] + function(config_table, dp_version, log_suffix) + local has_update + + local flavor = kong and + kong.configuration and + kong.configuration.router_flavor + -- remove this once the `expressions` flavor supports `route.snis` + if flavor == "expressions" then + return nil + end + + for _, route in ipairs(config_table.routes or {}) do + local snis = route.snis + if not snis or #snis == 0 then + break + end + + local idx = 0 + local new_snis = {} + local local_has_update + for _, sni in ipairs(snis) do + -- remove the sni that contains wildcard + if string_find(sni, "*", nil, true) then + has_update = true + local_has_update = true + + else + idx = idx + 1 + new_snis[idx] = sni + end + end + + if local_has_update then + route.snis = new_snis + end + end + + if has_update then + log_warn_message("configuration 'route.snis' contains elements that contains wildcard character '*'", + "be removed", dp_version, log_suffix) + end + + return has_update + end + }, + { 3006000000, --[[ 3.6.0.0 ]] function(config_table, dp_version, log_suffix) local has_update diff --git a/spec/01-unit/19-hybrid/03-compat_spec.lua b/spec/01-unit/19-hybrid/03-compat_spec.lua index b2a0030aa0f0..a7231dc2c4bc 100644 --- a/spec/01-unit/19-hybrid/03-compat_spec.lua +++ b/spec/01-unit/19-hybrid/03-compat_spec.lua @@ -630,5 +630,52 @@ describe("kong.clustering.compat", function() assert.is_nil(assert(services[3]).ca_certificates) end) - end) + end) -- describe + + + describe("route entities compatible changes", function() + it("route.snis contain wildcard", function() + for _, flavor in ipairs({"traditional", "traditional_compatible"}) do + local _, db = helpers.get_db_utils(nil, { + "routes", + }) + _G.kong.db = db + _G.kong.configuration = { router_flavor = flavor } + + assert(declarative.load_into_db({ + routes = { + route1 = { + id = "00000000-0000-0000-0000-000000000001", + snis = { "*.foo.test", "normal.test", "bar.*", "good.test" }, + }, + route2 = { + id = "00000000-0000-0000-0000-000000000002", + snis = { "normal.test", "good.test" }, + }, + route3 = { + id = "00000000-0000-0000-0000-000000000003", + snis = { "*.foo.test", "bar.*", }, + }, + }, + }, { _transform = true })) + local config = { config_table = declarative.export_config() } + local has_update, result = compat.update_compatible_payload(config, "3.6.0", "test_") + assert.truthy(has_update) + result = cjson_decode(inflate_gzip(result)).config_table + + local routes = assert(assert(result).routes) + assert.equals(3, #routes) + for _, route in ipairs(routes) do + if route.id == "00000000-0000-0000-0000-000000000003" then + assert.equals(0, #route.snis) + + else + assert.equals(2, #route.snis) + assert.same({"normal.test", "good.test"}, route.snis) + end + end + end + end) + end) -- describe + end)