Skip to content

Commit

Permalink
feat: upgrade goks to use Kong Gateway 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefero committed Sep 19, 2023
1 parent c369833 commit 887dddb
Show file tree
Hide file tree
Showing 14 changed files with 470 additions and 581 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DEFAULT_GOAL := all

GOKS_KONG_GATEWAY_VERSION ?= 3.0.0-ubuntu
GOKS_KONG_GATEWAY_VERSION ?= 3.4.0

.PHONY: gen-lua-tree
gen-lua-tree:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/lua-tree/share/lua/5.1/kong/db/schema/entities/certificates.lua b/lua-tree/share/lua/5.1/kong/db/schema/entities/certificates.lua
index dbe2d4a..a17dc93 100644
index 9e9127a..87060d2 100644
--- a/lua-tree/share/lua/5.1/kong/db/schema/entities/certificates.lua
+++ b/lua-tree/share/lua/5.1/kong/db/schema/entities/certificates.lua
@@ -1,6 +1,4 @@
Expand All @@ -9,7 +9,7 @@ index dbe2d4a..a17dc93 100644


local type = type
@@ -24,51 +22,5 @@ return {
@@ -25,51 +23,5 @@ return {

entity_checks = {
{ mutually_required = { "cert_alt", "key_alt" } },
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,89 @@
diff --git a/lua-tree/share/lua/5.1/kong/db/schema/entities/routes.lua b/lua-tree/share/lua/5.1/kong/db/schema/entities/routes.lua
index db0696f..da85443 100644
index 5c98e39..c1a346b 100644
--- a/lua-tree/share/lua/5.1/kong/db/schema/entities/routes.lua
+++ b/lua-tree/share/lua/5.1/kong/db/schema/entities/routes.lua
@@ -1,9 +1,8 @@
@@ -1,35 +1,8 @@
local typedefs = require("kong.db.schema.typedefs")
-local atc = require("kong.router.atc")
-local router = require("resty.router.router")
local deprecation = require("kong.deprecation")

-local validate_route
-local has_paths
-do
- local isempty = require("table.isempty")
- local CACHED_SCHEMA = require("kong.router.atc").schema
- local get_expression = require("kong.router.compat").get_expression
-
- local type = type
-
- -- works with both `traditional_compatiable` and `expressions` routes`
- validate_route = function(entity)
- local exp = entity.expression or get_expression(entity)
-
- local ok, err = router.validate(CACHED_SCHEMA, exp)
- if not ok then
- return nil, "Router Expression failed validation: " .. err
- end
-
- return true
- end
-
- has_paths = function(entity)
- local paths = entity.paths
- return type(paths) == "table" and not isempty(paths)
- end
-end
-
-local kong_router_flavor = kong and kong.configuration and kong.configuration.router_flavor
+-- ATC router is incompatible with goks
+local kong_router_flavor = "traditional"

if kong_router_flavor == "expressions" then
return {
@@ -70,20 +43,6 @@ if kong_router_flavor == "expressions" then
{ expression = { description = " The router expression.", type = "string", required = true }, },
{ priority = { description = "A number used to choose which route resolves a given request when several routes match it using regexes simultaneously.", type = "integer", required = true, default = 0 }, },
},
-
- entity_checks = {
- { custom_entity_check = {
- field_sources = { "expression", "id", },
- fn = function(entity)
- local ok, err = validate_route(entity)
- if not ok then
- return nil, err
- end
-
- return true
- end,
- } },
- },
}

-- router_flavor in ('traditional_compatible', 'traditional')
@@ -122,25 +81,6 @@ else
}},
}

- if kong_router_flavor == "traditional_compatible" then
- table.insert(entity_checks,
- { custom_entity_check = {
- run_with_missing_fields = true,
- field_sources = { "id", "paths", },
- fn = function(entity)
- if has_paths(entity) then
- local ok, err = validate_route(entity)
- if not ok then
- return nil, err
- end
- end
-
- return true
- end,
- }}
- )
- end
-
return {
name = "routes",
primary_key = { "id" },
75 changes: 48 additions & 27 deletions patches/005_lua-tree_share_lua_5_1_kong_db_schema_init_lua.patch
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
diff --git a/lua-tree/share/lua/5.1/kong/db/schema/init.lua b/lua-tree/share/lua/5.1/kong/db/schema/init.lua
index 489a666..9004e2e 100644
index 380c9e0..6e616e7 100644
--- a/lua-tree/share/lua/5.1/kong/db/schema/init.lua
+++ b/lua-tree/share/lua/5.1/kong/db/schema/init.lua
@@ -1,10 +1,7 @@
@@ -1,10 +1,8 @@
local tablex = require "pl.tablex"
local pretty = require "pl.pretty"
local utils = require "kong.tools.utils"
-local cjson = require "cjson"
-local new_tab = require "table.new"
-local is_reference = require "kong.pdk.vault".new().is_reference
-
-local nkeys = require "table.nkeys"
-local is_reference = require "kong.pdk.vault".is_reference
+
+local cjson = { array_mt = {} } --- TODO(hbagdi) XXX analyze the impact


local setmetatable = setmetatable
local getmetatable = getmetatable
@@ -38,10 +35,39 @@ local uuid = utils.uuid
@@ -39,10 +37,45 @@ local uuid = utils.uuid
local Schema = {}
Schema.__index = Schema

Expand Down Expand Up @@ -50,11 +51,17 @@ index 489a666..9004e2e 100644
+ end
+ end
+end
+
+function nkeys(t)
+ local count = 0
+ for _ in pairs(t) do count = count + 1 end
+ return count
+end
+

local validation_errors = {
-- general message
@@ -314,7 +340,7 @@ Schema.validators = {
@@ -315,7 +348,7 @@ Schema.validators = {
if #value ~= 36 then
return nil
end
Expand All @@ -63,18 +70,15 @@ index 489a666..9004e2e 100644
end,

contains = function(array, wanted)
@@ -1115,10 +1141,8 @@ validate_fields = function(self, input)
@@ -1115,7 +1148,6 @@ validate_fields = function(self, input)
pok, err, errors[k] = pcall(self.validate_field, self, input, v)
if not pok then
errors[k] = validation_errors.SCHEMA_CANNOT_VALIDATE
- kong.log.debug(errors[k], ": ", err)
end
elseif is_ttl then
- kong.log.debug("ignoring validation on ttl field")
else
field, err = resolve_field(self, k, field, subschema)
if field then
@@ -1207,12 +1231,6 @@ local function run_entity_check(self, name, input, arg, full_check, errors)

elseif not self.unvalidated_fields[k]() then
@@ -1207,12 +1239,6 @@ local function run_entity_check(self, name, input, arg, full_check, errors)
end
else
all_nil = false
Expand All @@ -87,7 +91,7 @@ index 489a666..9004e2e 100644
end
if errors[fname] then
all_ok = false
@@ -1249,7 +1267,7 @@ local function run_entity_check(self, name, input, arg, full_check, errors)
@@ -1252,7 +1278,7 @@ local function run_entity_check(self, name, input, arg, full_check, errors)

else
local error_fmt = validation_errors[name:upper()]
Expand All @@ -96,7 +100,7 @@ index 489a666..9004e2e 100644
if not err then
local data = pretty.write({ name = arg }):gsub("%s+", " ")
err = validation_errors.ENTITY_CHECK:format(name, data)
@@ -1649,14 +1667,7 @@ function Schema:process_auto_fields(data, context, nulls, opts)
@@ -1656,14 +1682,7 @@ function Schema:process_auto_fields(data, context, nulls, opts)
-- detected with ngx.ctx.KONG_PHASE, but to limit context
-- access we use nulls that admin api sets to true.
local kong = kong
Expand All @@ -112,7 +116,7 @@ index 489a666..9004e2e 100644

local refs
local prev_refs = resolve_references and data["$refs"]
@@ -1672,7 +1683,7 @@ function Schema:process_auto_fields(data, context, nulls, opts)
@@ -1679,7 +1698,7 @@ function Schema:process_auto_fields(data, context, nulls, opts)
end

elseif ftype == "string" then
Expand All @@ -121,7 +125,7 @@ index 489a666..9004e2e 100644
value = random_string()
end

@@ -1717,15 +1728,13 @@ function Schema:process_auto_fields(data, context, nulls, opts)
@@ -1728,17 +1747,11 @@ function Schema:process_auto_fields(data, context, nulls, opts)
refs = { [key] = value }
end

Expand All @@ -131,14 +135,16 @@ index 489a666..9004e2e 100644
value = deref

else
if err then
- if err then
- kong.log.warn("unable to resolve reference ", value, " (", err, ")")
else
- else
- kong.log.warn("unable to resolve reference ", value)
end
- end
-
value = nil
@@ -1756,15 +1765,13 @@ function Schema:process_auto_fields(data, context, nulls, opts)
end

@@ -1767,17 +1780,11 @@ function Schema:process_auto_fields(data, context, nulls, opts)

refs[key][i] = value[i]

Expand All @@ -148,10 +154,25 @@ index 489a666..9004e2e 100644
value[i] = deref

else
if err then
- if err then
- kong.log.warn("unable to resolve reference ", value[i], " (", err, ")")
else
- else
- kong.log.warn("unable to resolve reference ", value[i])
end
- end
-
value[i] = nil
end
end
@@ -1818,12 +1825,6 @@ function Schema:process_auto_fields(data, context, nulls, opts)
value[k] = deref

else
- if err then
- kong.log.warn("unable to resolve reference ", v, " (", err, ")")
- else
- kong.log.warn("unable to resolve reference ", v)
- end
-
value[k] = nil
end
end
Loading

0 comments on commit 887dddb

Please sign in to comment.