Skip to content

Commit

Permalink
feat(cp): add dp metadata on prem (KAG-2444)
Browse files Browse the repository at this point in the history
  • Loading branch information
gruceo committed Sep 20, 2023
1 parent bfc8ef7 commit 3771dfc
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG/unreleased/kong/11625.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"message": "**Clustering**: Allow configuring DP metadata labels for on-premise CP Gateway"
"type": "feature"
"scope": "Clustering"
"prs":
- 11625
"jiras":
- "KAG-2444"
1 change: 1 addition & 0 deletions kong-3.5.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ build = {
["kong.db.migrations.core.018_310_to_320"] = "kong/db/migrations/core/018_310_to_320.lua",
["kong.db.migrations.core.019_320_to_330"] = "kong/db/migrations/core/019_320_to_330.lua",
["kong.db.migrations.core.020_330_to_340"] = "kong/db/migrations/core/020_330_to_340.lua",
["kong.db.migrations.core.021_340_to_350"] = "kong/db/migrations/core/021_340_to_350.lua",
["kong.db.migrations.operations.200_to_210"] = "kong/db/migrations/operations/200_to_210.lua",
["kong.db.migrations.operations.212_to_213"] = "kong/db/migrations/operations/212_to_213.lua",
["kong.db.migrations.operations.280_to_300"] = "kong/db/migrations/operations/280_to_300.lua",
Expand Down
1 change: 1 addition & 0 deletions kong/clustering/control_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function _M:handle_cp_websocket()
ip = dp_ip,
version = dp_version,
sync_status = sync_status, -- TODO: import may have been failed though
labels = data.labels,
}, { ttl = purge_delay })
if not ok then
ngx_log(ngx_ERR, _log_prefix, "unable to update clustering data plane status: ", err, log_suffix)
Expand Down
13 changes: 13 additions & 0 deletions kong/db/migrations/core/021_340_to_350.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
return {
postgres = {
up = [[
DO $$
BEGIN
ALTER TABLE IF EXISTS ONLY "clustering_data_planes" ADD "labels" JSONB;
EXCEPTION WHEN DUPLICATE_COLUMN THEN
-- Do nothing, accept existing state
END;
$$;
]]
}
}
1 change: 1 addition & 0 deletions kong/db/migrations/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ return {
"018_310_to_320",
"019_320_to_330",
"020_330_to_340",
"021_340_to_350",
}
6 changes: 6 additions & 0 deletions kong/db/schema/entities/clustering_data_planes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@ return {
description = "The status of the clustering data planes sync.",
}
},
{ labels = { type = "map",
keys = { type = "string" },
values = { type = "string" },
description = "Custom key value pairs as meta-data for DPs.",
},
},
},
}
13 changes: 13 additions & 0 deletions spec/01-unit/01-db/01-schema/13-cluster_status_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,17 @@ describe("plugins", function()
assert.is_true(ok)
assert.is_nil(err)
end)

it("accepts labels", function()
local ok, err = validate({
ip = "127.0.0.1",
hostname = "dp.example.com",
labels = {
deployment = "mycloud",
region = "us-east-1"
}
})
assert.is_true(ok)
assert.is_nil(err)
end)
end)
8 changes: 7 additions & 1 deletion spec/02-integration/03-db/13-cluster_status_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ for _, strategy in helpers.each_strategy() do
{ config_hash = "a9a166c59873245db8f1a747ba9a80a7",
hostname = "localhost",
ip = "127.0.0.1",
labels = {
deployment = "mycloud",
region = "us-east-1",
}
})

assert.is_truthy(p)
Expand All @@ -39,7 +43,9 @@ for _, strategy in helpers.each_strategy() do
it(":update()", function()
-- this time update instead of insert
local p, err = db.clustering_data_planes:update({ id = "eb51145a-aaaa-bbbb-cccc-22087fb081db", },
{ config_hash = "a9a166c59873245db8f1a747ba9a80a7", })
{ config_hash = "a9a166c59873245db8f1a747ba9a80a7",
labels = { deployment = "aws", region = "us-east-2" }
})
assert.is_truthy(p)
assert.is_nil(err)
end)
Expand Down
5 changes: 4 additions & 1 deletion spec/02-integration/09-hybrid_mode/01-sync_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("CP/DP communication #" .. strategy, function()
cluster_control_plane = "127.0.0.1:9005",
proxy_listen = "0.0.0.0:9002",
nginx_conf = "spec/fixtures/custom_nginx.template",
cluster_dp_labels="deployment:mycloud,region:us-east-1",
}))

for _, plugin in ipairs(helpers.get_plugins_list()) do
Expand Down Expand Up @@ -69,7 +70,9 @@ describe("CP/DP communication #" .. strategy, function()
assert.near(14 * 86400, v.ttl, 3)
assert.matches("^(%d+%.%d+)%.%d+", v.version)
assert.equal(CLUSTERING_SYNC_STATUS.NORMAL, v.sync_status)

assert.equal(CLUSTERING_SYNC_STATUS.NORMAL, v.sync_status)
assert.equal("mycloud", v.labels.deployment)
assert.equal("us-east-1", v.labels.region)
return true
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/05-migration/db/migrations/core/021_340_to_350_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local uh = require "spec/upgrade_helpers"

describe("database migration", function()
uh.old_after_up("has created the expected new columns", function()
assert.table_has_column("clustering_data_planes", "labels", "jsonb")
end)
end)

0 comments on commit 3771dfc

Please sign in to comment.