mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
54 lines
1.8 KiB
Lua
54 lines
1.8 KiB
Lua
local hs = { status = "Progressing", message = "Waiting for " .. (obj.kind or "Policy") .. " status"}
|
|
|
|
local function is_policy_kind(kind)
|
|
return kind ~= nil and string.match(kind, "Policy$") ~= nil
|
|
end
|
|
|
|
if not is_policy_kind(obj.kind) then
|
|
return { status = "Healthy", message = obj.kind .. " is healthy" }
|
|
end
|
|
|
|
if obj.status ~= nil and obj.status.ancestors ~= nil then
|
|
if obj.metadata.generation ~= nil then
|
|
for i, ancestor in ipairs(obj.status.ancestors) do
|
|
for _, condition in ipairs(ancestor.conditions) do
|
|
if condition.observedGeneration == nil or condition.observedGeneration ~= obj.metadata.generation then
|
|
hs.message = "Waiting for Ancestor " .. (ancestor.ancestorRef.name or "") .. " to update " .. (obj.kind or "Policy") .. " status"
|
|
return hs
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
for i, ancestor in ipairs(obj.status.ancestors) do
|
|
local hasAcceptedCondition = false
|
|
for j, condition in ipairs(ancestor.conditions) do
|
|
if condition.type == "Accepted" then
|
|
hasAcceptedCondition = true
|
|
if condition.status ~= "True" then
|
|
hs.status = "Degraded"
|
|
hs.message = "Ancestor " .. (ancestor.ancestorRef.name or "") .. ": " .. condition.message
|
|
return hs
|
|
else
|
|
hs.status = "Healthy"
|
|
hs.message = (obj.kind or "Policy") .. " is healthy"
|
|
end
|
|
end
|
|
|
|
if condition.type == "ResolvedRefs" then
|
|
if condition.status ~= "True" then
|
|
hs.status = "Degraded"
|
|
hs.message = "Ancestor " .. (ancestor.ancestorRef.name or "") .. ": " .. condition.message
|
|
return hs
|
|
end
|
|
end
|
|
end
|
|
if not hasAcceptedCondition then
|
|
hs.status = "Degraded"
|
|
hs.message = "Ancestor " .. (ancestor.ancestorRef.name or "") .. ": " .. (obj.kind or "Policy") .. " is not accepted"
|
|
end
|
|
end
|
|
end
|
|
|
|
return hs
|