Skip to content

Commit

Permalink
fixes 1
Browse files Browse the repository at this point in the history
Signed-off-by: Aapo Talvensaari <[email protected]>
  • Loading branch information
bungle committed Sep 21, 2023
1 parent 461acc0 commit 42a038d
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 105 deletions.
2 changes: 1 addition & 1 deletion kong-3.5.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ build = {

["kong.clustering"] = "kong/clustering/init.lua",
["kong.clustering.data_plane"] = "kong/clustering/data_plane.lua",
["kong.clustering.data_plane_stream_protocol"] = "kong/clustering/protocol.lua",
["kong.clustering.protocol"] = "kong/clustering/protocol.lua",
["kong.clustering.control_plane"] = "kong/clustering/control_plane.lua",
["kong.clustering.utils"] = "kong/clustering/utils.lua",
["kong.clustering.events"] = "kong/clustering/events.lua",
Expand Down
28 changes: 14 additions & 14 deletions kong/clustering/compat/checkers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ end

local compatible_checkers = {
{ 3003000000, --[[ 3.3.0.0 ]]
function(config_table, dp_version, log_suffix)
function(config, dp_version, log_suffix)
local has_update

-- Support legacy queueing parameters for plugins that used queues prior to 3.3. `retry_count` has been
-- completely removed, so we always supply the default of 10 as that provides the same behavior as with a
-- pre 3.3 CP. The other queueing related legacy parameters can be determined from the new queue
-- configuration table.
for _, plugin in ipairs(config_table.plugins or {}) do
for _, plugin in ipairs(config.plugins or {}) do
local config = plugin.config

if plugin.name == 'statsd' or plugin.name == 'datadog' then
Expand Down Expand Up @@ -93,10 +93,10 @@ local compatible_checkers = {
},

{ 3003000000, --[[ 3.3.0.0 ]]
function(config_table, dp_version, log_suffix)
function(config, dp_version, log_suffix)
local has_update

for _, config_entity in ipairs(config_table.vaults or {}) do
for _, config_entity in ipairs(config.vaults or {}) do
if config_entity.name == "env" and type(config_entity.config) == "table" then
local config = config_entity.config
local prefix = config.prefix
Expand All @@ -116,7 +116,7 @@ local compatible_checkers = {
},

{ 3003000000, --[[ 3.3.0.0 ]]
function(config_table, dp_version, log_suffix)
function(config, dp_version, log_suffix)
-- remove updated_at field for core entities ca_certificates, certificates, consumers,
-- targets, upstreams, plugins, workspaces, clustering_data_planes and snis
local entity_names = {
Expand All @@ -128,7 +128,7 @@ local compatible_checkers = {
local updated_entities = {}

for _, name in ipairs(entity_names) do
for _, config_entity in ipairs(config_table[name] or {}) do
for _, config_entity in ipairs(config[name] or {}) do
if config_entity["updated_at"] then

config_entity["updated_at"] = nil
Expand All @@ -152,8 +152,8 @@ local compatible_checkers = {
},

{ 3002000000, --[[ 3.2.0.0 ]]
function(config_table, dp_version, log_suffix)
local config_services = config_table["services"]
function(config, dp_version, log_suffix)
local config_services = config["services"]
if not config_services then
return nil
end
Expand Down Expand Up @@ -188,8 +188,8 @@ local compatible_checkers = {
},

{ 3002000000, --[[ 3.2.0.0 ]]
function(config_table, dp_version, log_suffix)
local config_upstreams = config_table["upstreams"]
function(config, dp_version, log_suffix)
local config_upstreams = config["upstreams"]
if not config_upstreams then
return nil
end
Expand All @@ -214,8 +214,8 @@ local compatible_checkers = {
},

{ 3002000000, --[[ 3.2.0.0 ]]
function(config_table, dp_version, log_suffix)
local config_plugins = config_table["plugins"]
function(config, dp_version, log_suffix)
local config_plugins = config["plugins"]
if not config_plugins then
return nil
end
Expand All @@ -240,8 +240,8 @@ local compatible_checkers = {
},

{ 3001000000, --[[ 3.1.0.0 ]]
function(config_table, dp_version, log_suffix)
local config_upstreams = config_table["upstreams"]
function(config, dp_version, log_suffix)
local config_upstreams = config["upstreams"]
if not config_upstreams then
return nil
end
Expand Down
4 changes: 2 additions & 2 deletions kong/clustering/compat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@ function _M.update_compatible_payload(payload, dp_version, log_suffix)
local ver = checker[1]
local fn = checker[2]
if dp_version_num < ver then
fn(payload.config_table, dp_version, log_suffix)
fn(payload.config, dp_version, log_suffix)
end
end

local fields = get_removed_fields(dp_version_num)
if fields then
invalidate_keys_from_config(payload.config_table.plugins, fields, log_suffix, dp_version_num)
invalidate_keys_from_config(payload.config.plugins, fields, log_suffix, dp_version_num)
end

return payload
Expand Down
46 changes: 23 additions & 23 deletions kong/clustering/config_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,44 +138,44 @@ local function calculate_hash(input, o)
end


local function calculate_config_hash(config_table)
local function calculate_config_hash(config)
local o = buffer.new()
if type(config_table) ~= "table" then
local config_hash = calculate_hash(config_table, o)
if type(config) ~= "table" then
local config_hash = calculate_hash(config, o)
return config_hash, { config = config_hash, }
end

local routes = config_table.routes
local services = config_table.services
local plugins = config_table.plugins
local upstreams = config_table.upstreams
local targets = config_table.targets
local routes = config.routes
local services = config.services
local plugins = config.plugins
local upstreams = config.upstreams
local targets = config.targets

local routes_hash = calculate_hash(routes, o)
local services_hash = calculate_hash(services, o)
local plugins_hash = calculate_hash(plugins, o)
local upstreams_hash = calculate_hash(upstreams, o)
local targets_hash = calculate_hash(targets, o)

config_table.routes = nil
config_table.services = nil
config_table.plugins = nil
config_table.upstreams = nil
config_table.targets = nil
config.routes = nil
config.services = nil
config.plugins = nil
config.upstreams = nil
config.targets = nil

local rest_hash = calculate_hash(config_table, o)
local rest_hash = calculate_hash(config, o)
local config_hash = ngx_md5(routes_hash ..
services_hash ..
plugins_hash ..
upstreams_hash ..
targets_hash ..
rest_hash)

config_table.routes = routes
config_table.services = services
config_table.plugins = plugins
config_table.upstreams = upstreams
config_table.targets = targets
config.routes = routes
config.services = services
config.plugins = plugins
config.upstreams = upstreams
config.targets = targets

return config_hash, {
config = config_hash,
Expand All @@ -202,11 +202,11 @@ local function fill_empty_hashes(hashes)
end
end

function _M.update(declarative_config, config_table, config_hash, hashes)
assert(type(config_table) == "table")
function _M.update(declarative_config, config, config_hash, hashes)
assert(type(config) == "table")

if not config_hash then
config_hash, hashes = calculate_config_hash(config_table)
config_hash, hashes = calculate_config_hash(config)
end

if hashes then
Expand All @@ -221,7 +221,7 @@ function _M.update(declarative_config, config_table, config_hash, hashes)
end

local entities, err, _, meta, new_hash =
declarative_config:parse_table(config_table, config_hash)
declarative_config:parse_table(config, config_hash)
if not entities then
return nil, "bad config received from control plane " .. err
end
Expand Down
25 changes: 15 additions & 10 deletions kong/clustering/protocol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local tostring = tostring


local LMDB_TXN
local META
local HASH
local ENTITY_NAME
local KEYS_BY_WS
Expand Down Expand Up @@ -66,7 +67,10 @@ local function send_configuration_payload(wb, payload)
type = "reconfigure:start",
hash = hash,
meta = {
timestamp = timetamp,
format_version = config._format_version,
default_workspace = kong.default_workspace,
hashes = hashes,
}
})

Expand Down Expand Up @@ -107,15 +111,13 @@ local function send_configuration_payload(wb, payload)
send_binary(wb, {
type = "reconfigure:end",
hash = hash,
hashes = hashes,
default_workspace = kong.default_workspace,
timestamp = timetamp,
})
end


local function reset_values()
LMDB_TXN = nil
META = nil
HASH = nil
ENTITY_NAME = nil
KEYS_BY_WS = nil
Expand All @@ -133,6 +135,7 @@ local function reconfigure_start(msg)
LMDB_TXN:db_drop(false)

HASH = msg.hash
META = msg.meta
KEYS_BY_WS = { ["*"] = {} }
PAGE_FOR = {}
TAGS = {}
Expand Down Expand Up @@ -248,13 +251,15 @@ local function process_entities(msg)

local id = pk_string(schema, entity)
local ws_id
if schema.workspaceable and entity.ws_id ~= null then
if schema.workspaceable then
if not entity.ws_id or entity.ws_id == null then
entity.ws_id = META.default_workspace
end
ws_id = entity.ws_id
end
local ws = ws_id or ""
local cache_key = dao:cache_key(id, nil, nil, nil, nil, ws_id)
local entity_marshalled = assert(marshall(entity))

LMDB_TXN:set(cache_key, entity_marshalled)
LMDB_TXN:set(dao:cache_key(id, nil, nil, nil, nil, "*"), entity_marshalled)
if schema.cache_key then
Expand Down Expand Up @@ -312,11 +317,11 @@ local function process_entities(msg)
end


local function get_reconfigure_data(msg)
local function get_reconfigure_data()
local router_hash = DECLARATIVE_EMPTY_CONFIG_HASH
local plugins_hash = DECLARATIVE_EMPTY_CONFIG_HASH
local balancer_hash = DECLARATIVE_EMPTY_CONFIG_HASH
local hashes = msg.hashes
local hashes = META.hashes
if hashes then
local routes_hash = hashes.routes or DECLARATIVE_EMPTY_CONFIG_HASH
local services_hash = hashes.services or DECLARATIVE_EMPTY_CONFIG_HASH
Expand All @@ -338,7 +343,7 @@ local function get_reconfigure_data(msg)
end

return {
msg.default_workspace or kong.default_workspace,
META.default_workspace,
router_hash,
plugins_hash,
balancer_hash,
Expand All @@ -355,10 +360,10 @@ local function reconfigure_end(msg)
LMDB_TXN:set("tags:" .. tag .. "|@list", assert(marshall(tags)))
end
LMDB_TXN:set("tags||@list", assert(marshall(TAGS)))
LMDB_TXN:set(DECLARATIVE_HASH_KEY, msg.hash)
LMDB_TXN:set(DECLARATIVE_HASH_KEY, HASH)
assert(LMDB_TXN:commit())
assert(events.declarative_reconfigure_notify(get_reconfigure_data()))
reset_values()
assert(events.declarative_reconfigure_notify(get_reconfigure_data(msg)))
end


Expand Down
7 changes: 7 additions & 0 deletions kong/plugins/key-auth/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ local ERR_UNEXPECTED = { status = 500, message = "An unexpected error o


local function load_credential(key)
ngx.log(ngx.ERR, "LOADING CREDENTIAL")
ngx.log(ngx.ERR, "KEY: ", key)

local cred, err = kong.db.keyauth_credentials:select_by_key(key)

kong.log.inspect(cred)
kong.log.inspect(err)

if not cred then
return nil, err
end
Expand Down
Loading

0 comments on commit 42a038d

Please sign in to comment.