diff --git a/kong/db/dao/workspaces.lua b/kong/db/dao/workspaces.lua index 659b98bc9255..f93531292467 100644 --- a/kong/db/dao/workspaces.lua +++ b/kong/db/dao/workspaces.lua @@ -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() @@ -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) diff --git a/kong/db/strategies/off/init.lua b/kong/db/strategies/off/init.lua index dda41efbed28..34877097eb6f 100644 --- a/kong/db/strategies/off/init.lua +++ b/kong/db/strategies/off/init.lua @@ -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