Skip to content

Commit

Permalink
put the socket subdir name into a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh committed Jul 30, 2024
1 parent e4974c9 commit 4465375
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local pl_path = require "pl.path"
local tablex = require "pl.tablex"
local log = require "kong.cmd.utils.log"
local env = require "kong.cmd.utils.env"
local constants = require "kong.constants"


local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy
Expand Down Expand Up @@ -484,7 +485,7 @@ local function load(path, custom_conf, opts)

-- the socket path is where we store listening unix sockets for IPC and
-- private APIs
conf.socket_path = pl_path.join(conf.prefix, "sockets")
conf.socket_path = pl_path.join(conf.prefix, constants.SOCKET_DIRECTORY)

if conf.lua_ssl_trusted_certificate
and #conf.lua_ssl_trusted_certificate > 0 then
Expand Down
2 changes: 2 additions & 0 deletions kong/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ local constants = {
service = "upstream",
}
},

SOCKET_DIRECTORY = "sockets",
}

for _, v in ipairs(constants.CLUSTERING_SYNC_STATUS) do
Expand Down
3 changes: 2 additions & 1 deletion kong/runloop/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ do
if not socket_path then
-- `kong.configuration.socket_path` is already normalized to an absolute
-- path, but `ngx.config.prefix()` is not
socket_path = require("pl.path").abspath(ngx.config.prefix() .. "/sockets")
socket_path = require("pl.path").abspath(ngx.config.prefix() .. "/"
.. constants.SOCKET_DIRECTORY)
end

local STREAM_CONFIG_SOCK = "unix:" .. socket_path .. "/stream_config.sock"
Expand Down
4 changes: 3 additions & 1 deletion kong/tools/stream_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-- may changed or be removed in the future Kong releases once a better mechanism
-- for inter subsystem communication in OpenResty became available.

local constants = require "kong.constants"
local lpack = require "lua_pack"

local kong = kong
Expand Down Expand Up @@ -38,7 +39,8 @@ local MAX_DATA_LEN = 2^22 - 1
local HEADER_LEN = #st_pack(PACK_F, MAX_KEY_LEN, MAX_DATA_LEN)

-- this module may be loaded before `kong.configuration` is initialized
local SOCKET_PATH = "unix:" .. ngx.config.prefix() .. "/sockets/stream_rpc.sock"
local SOCKET_PATH = "unix:" .. ngx.config.prefix() .. "/"
.. constants.SOCKET_DIRECTORY .. "/stream_rpc.sock"

local stream_api = {}

Expand Down
2 changes: 1 addition & 1 deletion spec/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3844,7 +3844,7 @@ end
local function cleanup_kong(prefix, preserve_prefix, preserve_dc)
-- remove socket files to ensure `pl.dir.rmtree()` ok
prefix = prefix or conf.prefix
local socket_path = pl_path.join(prefix, "sockets")
local socket_path = pl_path.join(prefix, constants.SOCKET_DIRECTORY)
for child in lfs.dir(socket_path) do
if child:sub(-5) == ".sock" then
local path = pl_path.join(socket_path, child)
Expand Down

0 comments on commit 4465375

Please sign in to comment.