Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(clustering/sync): prioritize using entity ws_id during validation #14296

Merged
merged 4 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions kong/db/schema/others/declarative_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,15 @@ function DeclarativeConfig.validate_references_sync(deltas, deltas_map, is_full_
for _, delta in ipairs(deltas) do
local item_type = delta.type
local item = delta.entity
local ws_id = delta.ws_id or kong.default_workspace

local foreign_refs = foreign_references[item_type]

if not item or item == null or not foreign_refs then
goto continue
end

local ws_id = item.ws_id or delta.ws_id or kong.default_workspace

for k, v in pairs(item) do

-- Try to check if item's some foreign key exists in the deltas or LMDB.
Expand All @@ -550,7 +551,7 @@ function DeclarativeConfig.validate_references_sync(deltas, deltas_map, is_full_
errs[item_type] = errs[item_type] or {}
errs[item_type][foreign_entity] = errs[item_type][foreign_entity] or {}

local msg = fmt("could not find %s's foreign refrences %s (%s)",
local msg = fmt("could not find %s's foreign references %s (%s)",
item_type, foreign_entity,
type(v) == "string" and v or cjson_encode(v))

Expand Down
8 changes: 4 additions & 4 deletions spec/01-unit/19-hybrid/04-validate_deltas_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,19 @@ describe("[delta validations]",function()
local _, err, err_t = validate_deltas(deltas, false)

assert.matches(
"entry 1 of 'services': could not find routes's foreign refrences services",
"entry 1 of 'services': could not find routes's foreign references services",
err)

assert.same(err_t, {
code = 21,
fields = {
routes = {
services = {
"could not find routes's foreign refrences services ({\"id\":\"00000000-0000-0000-0000-000000000000\"})",
"could not find routes's foreign references services ({\"id\":\"00000000-0000-0000-0000-000000000000\"})",
},
},
},
message = [[sync deltas is invalid: {routes={services={"could not find routes's foreign refrences services ({\"id\":\"00000000-0000-0000-0000-000000000000\"})"}}}]],
message = [[sync deltas is invalid: {routes={services={"could not find routes's foreign references services ({\"id\":\"00000000-0000-0000-0000-000000000000\"})"}}}]],
flattened_errors = {},
name = "sync deltas parse failure",
source = "kong.clustering.services.sync.validate.validate_deltas",
Expand Down Expand Up @@ -350,7 +350,7 @@ describe("[delta validations]",function()
for i = 1, 100 do
assert.matches(
"entry " .. i .. " of 'services': " ..
"could not find routes's foreign refrences services",
"could not find routes's foreign references services",
err)
end
end)
Expand Down
Loading