Skip to content

Commit

Permalink
cpu detection: early closing of file pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Sep 26, 2023
1 parent 27bc7cf commit 90403c2
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions gateway/src/apicast/cli/environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ local function parse_nameservers()
end
end

local function detect_kubernetes()
local secrets = open('/run/secrets/kubernetes.io')

if secrets then secrets:close() end

return secrets or resty_env.value('KUBERNETES_PORT')
end

-- CPU shares in Cgroups v1 or converted from weight in Cgroups v2 in millicores
local function cpu_shares()
local shares
Expand All @@ -66,9 +58,9 @@ local function cpu_shares()

if file then
local weight = file:read('*n')
shares = (((weight - 1) * 262142) / 9999) + 2

file:close()

shares = (((weight - 1) * 262142) / 9999) + 2
end
else
-- Cgroups v1
Expand Down

0 comments on commit 90403c2

Please sign in to comment.