From 23e709c151d5f7e1bf0d8d9dffd5879ebe26758c Mon Sep 17 00:00:00 2001 From: Douglas Lee Date: Tue, 21 Feb 2023 18:19:33 +0800 Subject: [PATCH] docs(changelog): add entry for renamed kong.conf properties (#10310) --- kong/db/dao/init.lua | 3 ++- kong/db/dao/targets.lua | 3 ++- kong/db/strategies/postgres/connector.lua | 3 ++- kong/pdk/table.lua | 17 +++-------------- kong/plugins/opentelemetry/otlp.lua | 2 +- kong/tools/utils.lua | 17 +++++++++-------- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/kong/db/dao/init.lua b/kong/db/dao/init.lua index 55892b20bd08..df9bf648d44a 100644 --- a/kong/db/dao/init.lua +++ b/kong/db/dao/init.lua @@ -22,6 +22,7 @@ local log = ngx.log local fmt = string.format local match = string.match local run_hook = hooks.run_hook +local table_merge = utils.table_merge local ERR = ngx.ERR @@ -156,7 +157,7 @@ local function get_pagination_options(self, options) options = utils.deep_copy(options, false) if type(options.pagination) == "table" then - options.pagination = utils.table_merge(self.pagination, options.pagination) + options.pagination = table_merge(self.pagination, options.pagination) else options.pagination = self.pagination diff --git a/kong/db/dao/targets.lua b/kong/db/dao/targets.lua index 93b456183a0c..f6168919dc15 100644 --- a/kong/db/dao/targets.lua +++ b/kong/db/dao/targets.lua @@ -10,6 +10,7 @@ local ipairs = ipairs local table = table local type = type local min = math.min +local table_merge = utils.table_merge local _TARGETS = {} @@ -197,7 +198,7 @@ function _TARGETS:page_for_upstream(upstream_pk, size, offset, options) local pagination = self.pagination if type(options) == "table" and type(options.pagination) == "table" then - pagination = utils.table_merge(pagination, options.pagination) + pagination = table_merge(pagination, options.pagination) end if not size then diff --git a/kong/db/strategies/postgres/connector.lua b/kong/db/strategies/postgres/connector.lua index 1a5c6a4540bd..0f99a17dcf7b 100644 --- a/kong/db/strategies/postgres/connector.lua +++ b/kong/db/strategies/postgres/connector.lua @@ -30,6 +30,7 @@ local fmt = string.format local sub = string.sub local utils_toposort = utils.topological_sort local insert = table.insert +local table_merge = utils.table_merge local WARN = ngx.WARN @@ -1005,7 +1006,7 @@ function _M.new(kong_config) end end - local config_ro = utils.table_merge(config, ro_override) + local config_ro = table_merge(config, ro_override) local sem if config_ro.sem_max > 0 then diff --git a/kong/pdk/table.lua b/kong/pdk/table.lua index fbbd00e4150d..d9e66c63b64a 100644 --- a/kong/pdk/table.lua +++ b/kong/pdk/table.lua @@ -1,3 +1,5 @@ +local table_merge = require("kong.tools.utils").table_merge + --- Utilities for Lua tables. -- -- @module kong.table @@ -48,20 +50,7 @@ local clear_tab = require "table.clear" -- local t1 = {1, 2, 3, foo = "f"} -- local t2 = {4, 5, bar = "b"} -- local t3 = kong.table.merge(t1, t2) -- {4, 5, 3, foo = "f", bar = "b"} -local function merge_tab(t1, t2) - local res = {} - if t1 then - for k,v in pairs(t1) do - res[k] = v - end - end - if t2 then - for k,v in pairs(t2) do - res[k] = v - end - end - return res -end +local merge_tab = table_merge local function new(self) diff --git a/kong/plugins/opentelemetry/otlp.lua b/kong/plugins/opentelemetry/otlp.lua index d84c5c7d97fb..1d1523a94e4c 100644 --- a/kong/plugins/opentelemetry/otlp.lua +++ b/kong/plugins/opentelemetry/otlp.lua @@ -10,7 +10,7 @@ local insert = table.insert local tablepool_fetch = tablepool.fetch local tablepool_release = tablepool.release local deep_copy = utils.deep_copy -local table_merge = utils.table_merge +local table_merge = kong.table.merge local POOL_OTLP = "KONG_OTLP" local EMPTY_TAB = {} diff --git a/kong/tools/utils.lua b/kong/tools/utils.lua index d518296eb856..e985a58c3f30 100644 --- a/kong/tools/utils.lua +++ b/kong/tools/utils.lua @@ -474,16 +474,17 @@ end -- @param t2 The second table -- @return The (new) merged table function _M.table_merge(t1, t2) - if not t1 then - t1 = {} + local res = {} + if t1 then + for k,v in pairs(t1) do + res[k] = v + end end - if not t2 then - t2 = {} + if t2 then + for k,v in pairs(t2) do + res[k] = v + end end - - local res = {} - for k,v in pairs(t1) do res[k] = v end - for k,v in pairs(t2) do res[k] = v end return res end