Skip to content

Instantly share code, notes, and snippets.

@MaxAnderson95
Created August 28, 2024 17:17
Show Gist options
  • Save MaxAnderson95/e73648c12a5d8ebadb374bf5c7ff7c93 to your computer and use it in GitHub Desktop.
Save MaxAnderson95/e73648c12a5d8ebadb374bf5c7ff7c93 to your computer and use it in GitHub Desktop.

Revisions

  1. MaxAnderson95 created this gist Aug 28, 2024.
    37 changes: 37 additions & 0 deletions health.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    -- Create a table to store the health status of the object
    local hs = {}

    -- Check if the object has any status at all
    if obj.status ~= nil then
    -- Check if the object has any conditions at all
    if obj.status.conditions ~= nil then
    -- Loop through each condition
    for i, condition in ipairs(obj.status.conditions) do
    -- If the "Ready" condition is False
    if condition.type == "Ready" and condition.status == "False" then
    -- Check the severity. If "Error" return a status of "Degraded"
    if condition.severity == "Error" then
    hs.status = "Degraded"
    hs.message = condition.message
    return hs
    -- For any other severity return a status of "Progressing"
    else
    hs.status = "Progressing"
    hs.message = condition.message
    return hs
    end
    end
    -- Once the "Ready" condition is "True", return status of "Healthy"
    if condition.type == "Ready" and condition.status == "True" then
    hs.status = "Healthy"
    hs.message = condition.message
    return hs
    end
    end
    end
    end

    -- If object status is nil or status.conditions are nil, return Degraded
    hs.status = "Degraded"
    hs.message = "Waiting for ASO Operator to begin reconsiling the object"
    return hs