Skip to content

Commit

Permalink
Fix Policy/policy.open-cluster-management.io health check
Browse files Browse the repository at this point in the history
Tried using the health check as listed here but it gave error:

| error setting app health: failed to get resource health for "Policy" with name "XXXX" in namespace "local-cluster": <string>:35: invalid value (nil) at index 1 in table for concat stack traceback: [G]: in function 'concat' <string>:35: in main chunk [G]: ?

This change fixes the error by updating how the noncompliant clusters are tracked and counted to use latest Lua recommendations. 

Signed-off-by: Ian Tewksbury <[email protected]>
  • Loading branch information
itewk authored Sep 25, 2024
1 parent f03146d commit 7c4f98b
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ if obj.status.status ~= nil then
-- "root" policy
for i, entry in ipairs(obj.status.status) do
if entry.compliant ~= "Compliant" then
noncompliants[i] = entry.clustername
table.insert(noncompliants, entry.clustername)
end
end
if table.getn(noncompliants) == 0 then
if #noncompliants == 0 then
hs.message = "All clusters are compliant"
else
hs.message = "NonCompliant clusters: " .. table.concat(noncompliants, ", ")
Expand All @@ -26,10 +26,10 @@ elseif obj.status.details ~= nil then
-- "replicated" policy
for i, entry in ipairs(obj.status.details) do
if entry.compliant ~= "Compliant" then
noncompliants[i] = entry.templateMeta.name
table.insert(noncompliants, entry.templateMeta.name)
end
end
if table.getn(noncompliants) == 0 then
if #noncompliants == 0 then
hs.message = "All templates are compliant"
else
hs.message = "NonCompliant templates: " .. table.concat(noncompliants, ", ")
Expand Down

0 comments on commit 7c4f98b

Please sign in to comment.