-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
local cjson = require "cjson.safe" | ||
local pl_tablex = require "pl.tablex" | ||
|
||
local fmt = string.format | ||
local re_match = ngx.re.match | ||
|
||
local MAX_KEY_SIZE = 63 | ||
local MAX_VALUE_SIZE = MAX_KEY_SIZE | ||
local MAX_KEYS = 10 | ||
|
||
local BASE_PTRN = "[a-z0-9]([\\w\\.:-]*[a-z0-9]|)$" | ||
local KEY_PTRN = "(?!kong)(?!konnect)(?!insomnia)(?!mesh)(?!kic)" .. BASE_PTRN | ||
local VAL_PTRN = BASE_PTRN | ||
|
||
|
||
local function validate_table(labels_t) | ||
return pl_tablex.size(labels_t) <= MAX_KEYS | ||
end | ||
|
||
|
||
local function validate_pattern(str, max_size, pattern) | ||
if str == "" or #str > max_size then | ||
return false, fmt( | ||
"%s must have between 1 and %d characters", str, max_size) | ||
end | ||
if not re_match(str, pattern, "ajoi") then | ||
return false, fmt("%s not conforming with pattern %s", str, pattern) | ||
end | ||
return true | ||
end | ||
|
||
|
||
local function load_labels() | ||
local labels, err = cjson.decode(kong.configuration.cluster_dp_labels or "{}") | ||
if not labels then | ||
return nil, err | ||
end | ||
|
||
local ok | ||
ok, err = validate_table(labels) | ||
if not ok then | ||
return nil, "labels validation failed: " .. err | ||
end | ||
|
||
for k, v in pairs(labels) do | ||
ok, err = validate_pattern(k, MAX_KEY_SIZE, KEY_PTRN) | ||
if not ok then | ||
return nil, "label name validation failed: " .. err | ||
end | ||
ok, err = validate_pattern(v, MAX_VALUE_SIZE, VAL_PTRN) | ||
if not ok then | ||
return nil, "label value validation failed: " .. err | ||
end | ||
end | ||
|
||
return labels | ||
end | ||
|
||
|
||
return { | ||
load_labels = load_labels | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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; | ||
$$; | ||
]] | ||
}, | ||
|
||
cassandra = { | ||
up = [[ | ||
ALTER TABLE clustering_data_planes ADD labels map<text,text>; | ||
]] | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ return { | |
"016_280_to_300", | ||
"017_300_to_310", | ||
"018_310_to_320", | ||
"019_320_to_330", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,6 @@ return { | |
default = "unknown", | ||
} | ||
}, | ||
{ labels = typedefs.labels }, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "map<text,text>") | ||
end) | ||
end) |