Skip to content

Commit

Permalink
return default workspace constant value if master could not get it fr…
Browse files Browse the repository at this point in the history
…om lmdb
  • Loading branch information
chobits committed Oct 11, 2024
1 parent 2838ffd commit 2090740
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions kong/db/dao/workspaces.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local lmdb = require("resty.lmdb")


local DECLARATIVE_DEFAULT_WORKSPACE_KEY = constants.DECLARATIVE_DEFAULT_WORKSPACE_KEY
local DECLARATIVE_DEFAULT_WORKSPACE_ID = constants.DECLARATIVE_DEFAULT_WORKSPACE_ID


function Workspaces:truncate()
Expand All @@ -27,12 +28,13 @@ end

function Workspaces:select_by_name(key, options)
if kong.configuration.database == "off" and key == "default" then
-- We can ensure that when starting in dbless mode, lmdb will by default
-- insert a 'default' workspace. If this Kong is a dataplane, it will later
-- synchronize the configuration from the CP and overwrite this default one.
-- TODO: Currently, only Kong workers load the declarative config into lmdb.
-- The Kong master doesn't get the default workspace from lmdb, so we
-- return the default constant value. It would be better to have the
-- Kong master load the declarative config into lmdb in the future.
--
-- it should be a table, not a single string
return { id = lmdb.get(DECLARATIVE_DEFAULT_WORKSPACE_KEY), }
return { id = lmdb.get(DECLARATIVE_DEFAULT_WORKSPACE_KEY) or DECLARATIVE_DEFAULT_WORKSPACE_ID, }
end

return self.super.select_by_name(self, key, options)
Expand Down
4 changes: 2 additions & 2 deletions kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ local UNINIT_WORKSPACE_ID = "00000000-0000-0000-0000-000000000000"

local function get_default_workspace()
if kong.default_workspace == UNINIT_WORKSPACE_ID then
local res = assert(kong.db.workspaces:select_by_name("default"))
kong.default_workspace = res.id
local res = kong.db.workspaces:select_by_name("default")
kong.default_workspace = assert(res and res.id)
end

return kong.default_workspace
Expand Down

0 comments on commit 2090740

Please sign in to comment.