|
| 1 | +local hs = { status = "Progressing", message = "Waiting for " .. (obj.kind or "Policy") .. " status"} |
| 2 | + |
| 3 | +local function is_policy_kind(kind) |
| 4 | + return kind ~= nil and string.match(kind, "Policy$") ~= nil |
| 5 | +end |
| 6 | + |
| 7 | +if not is_policy_kind(obj.kind) then |
| 8 | + return { status = "Healthy", message = obj.kind .. " is healthy" } |
| 9 | +end |
| 10 | + |
| 11 | +if obj.status ~= nil and obj.status.ancestors ~= nil then |
| 12 | + if obj.metadata.generation ~= nil then |
| 13 | + for i, ancestor in ipairs(obj.status.ancestors) do |
| 14 | + for _, condition in ipairs(ancestor.conditions) do |
| 15 | + if condition.observedGeneration == nil or condition.observedGeneration ~= obj.metadata.generation then |
| 16 | + hs.message = "Waiting for Ancestor " .. (ancestor.ancestorRef.name or "") .. " to update " .. (obj.kind or "Policy") .. " status" |
| 17 | + return hs |
| 18 | + end |
| 19 | + end |
| 20 | + end |
| 21 | + end |
| 22 | + |
| 23 | + for i, ancestor in ipairs(obj.status.ancestors) do |
| 24 | + local hasAcceptedCondition = false |
| 25 | + for j, condition in ipairs(ancestor.conditions) do |
| 26 | + if condition.type == "Accepted" then |
| 27 | + hasAcceptedCondition = true |
| 28 | + if condition.status ~= "True" then |
| 29 | + hs.status = "Degraded" |
| 30 | + hs.message = "Ancestor " .. (ancestor.ancestorRef.name or "") .. ": " .. condition.message |
| 31 | + return hs |
| 32 | + else |
| 33 | + hs.status = "Healthy" |
| 34 | + hs.message = (obj.kind or "Policy") .. " is healthy" |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + if condition.type == "ResolvedRefs" then |
| 39 | + if condition.status ~= "True" then |
| 40 | + hs.status = "Degraded" |
| 41 | + hs.message = "Ancestor " .. (ancestor.ancestorRef.name or "") .. ": " .. condition.message |
| 42 | + return hs |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | + if not hasAcceptedCondition then |
| 47 | + hs.status = "Degraded" |
| 48 | + hs.message = "Ancestor " .. (ancestor.ancestorRef.name or "") .. ": " .. (obj.kind or "Policy") .. " is not accepted" |
| 49 | + end |
| 50 | + end |
| 51 | +end |
| 52 | + |
| 53 | +return hs |
0 commit comments