Skip to content

Commit

Permalink
add compatible check code
Browse files Browse the repository at this point in the history
  • Loading branch information
catbro666 committed Apr 1, 2024
1 parent 7e37da3 commit 40646a5
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
48 changes: 48 additions & 0 deletions kong/clustering/compat/checkers.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local ipairs = ipairs
local type = type
local string_find = string.find


local log_warn_message
Expand All @@ -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
Expand Down
49 changes: 48 additions & 1 deletion spec/01-unit/19-hybrid/03-compat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 40646a5

Please sign in to comment.