github.com/argoproj/argo-cd/v3@v3.2.1/resource_customizations/numaplane.numaproj.io/NumaflowControllerRollout/health.lua (about)

     1  -- return true if degraded, along with the reason
     2  function isDegraded(obj) 
     3    if obj.status == nil then 
     4      return false, ""
     5    end
     6    -- check phase=Failed, healthy condition failed
     7    if obj.status.phase == "Failed" then
     8      return true, obj.status.message
     9    end
    10  
    11    if obj.status.conditions ~= nil then
    12      for i, condition in ipairs(obj.status.conditions) do
    13        if condition.type == "ChildResourcesHealthy" and condition.status == "False" and condition.reason ~= "Progressing" then
    14          return true, condition.message
    15        end
    16      end
    17    end
    18  
    19    return false, ""
    20  end
    21  
    22  function isProgressing(obj) 
    23    -- if there's no Status at all, we haven't been reconciled
    24    if obj.status == nil then 
    25      return true, "Not yet reconciled"
    26    end
    27  
    28    if obj.metadata.generation ~= obj.status.observedGeneration then
    29      return true, "Not yet reconciled"
    30    end
    31  
    32    -- if we are in the middle of an upgrade
    33    if obj.status.upgradeInProgress ~= nil and obj.status.upgradeInProgress ~= "" or obj.status.phase == "Pending" then
    34      return true, "Update in progress"
    35    end
    36  
    37    -- if the child is Progressing
    38    if obj.status.conditions ~= nil then
    39      for i, condition in ipairs(obj.status.conditions) do
    40        if condition.type == "ChildResourcesHealthy" and condition.status == "False" and condition.reason == "Progressing" then
    41          return true, "Child Progressing"
    42        end
    43      end
    44    end
    45  
    46    return false, ""
    47  end
    48  
    49  -- return true if healthy, along with the reason
    50  function isHealthy(obj)
    51    if obj.status == nil then 
    52      return false, ""
    53    end
    54  
    55    if obj.status.conditions ~= nil then
    56      for i, condition in ipairs(obj.status.conditions) do
    57        if condition.type == "ChildResourcesHealthy" and condition.status == "True" then
    58          return true, "Healthy"
    59        end
    60      end
    61    end
    62  end
    63  
    64  local hs = {}
    65  
    66  
    67  progressing, reason = isProgressing(obj)
    68  if progressing then
    69    hs.status = "Progressing"
    70    hs.message = reason
    71    return hs
    72  end
    73  
    74  degraded, reason = isDegraded(obj)
    75  if degraded then
    76    hs.status = "Degraded"
    77    hs.message = reason
    78    return hs
    79  end
    80  
    81  healthy, reason = isHealthy(obj)
    82  if healthy then
    83    hs.status = "Healthy"
    84    hs.message = reason
    85    return hs
    86  end
    87  
    88  hs.status = "Unknown"
    89  hs.message = "Unknown status"
    90  return hs