Skip to content

Commit

Permalink
fix(clustering/sync): prioritize using entity ws_id during validation (
Browse files Browse the repository at this point in the history
  • Loading branch information
chobits authored Feb 20, 2025
1 parent 7fcde18 commit e20ab83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
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 @@ -284,19 +284,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 @@ -366,7 +366,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

1 comment on commit e20ab83

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong-dev:e20ab83e20f7d285a3d4bd8ad39ec59aa0b49610
Artifacts available https://github.com/Kong/kong/actions/runs/13430876993

Please # to comment.