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

     1  -- return true if paused, along with the reason
     2  function isPaused(obj)
     3    if obj.status == nil then 
     4      return false, ""
     5    end
     6  
     7    if obj.status.conditions ~= nil then
     8      for i, condition in ipairs(obj.status.conditions) do
     9        if condition.type == "MonoVertexPausingOrPaused" and condition.status == "True" then
    10          return true, condition.message
    11        end
    12      end
    13    end
    14  end
    15  
    16  
    17  
    18  -- return true if degraded, along with the reason
    19  function isDegraded(obj) 
    20    if obj.status == nil then 
    21      return false, ""
    22    end
    23    -- check phase=Failed, healthy condition failed, progressive upgrade failed
    24    if obj.status.phase == "Failed" then
    25      return true, obj.status.message
    26    end
    27  
    28    if obj.status.conditions ~= nil then
    29      for i, condition in ipairs(obj.status.conditions) do
    30        if condition.type == "ChildResourcesHealthy" and condition.status == "False" and condition.reason == "MonoVertexFailed" then
    31          return true, condition.message
    32        elseif condition.type == "ProgressiveUpgradeSucceeded" and condition.status == "False" then
    33          return true, "Progressive upgrade failed"
    34        end
    35      end
    36    end
    37  
    38    return false, ""
    39  end
    40  
    41  function isProgressing(obj) 
    42    -- if there's no Status at all, we haven't been reconciled
    43    if obj.status == nil then 
    44      return true, "Not yet reconciled"
    45    end
    46  
    47    if obj.metadata.generation ~= obj.status.observedGeneration then
    48      return true, "Not yet reconciled"
    49    end
    50  
    51    -- if we are in the middle of an upgrade
    52    if obj.status.upgradeInProgress ~= nil and obj.status.upgradeInProgress ~= "" or obj.status.phase == "Pending" then
    53      -- first check if Progressive Upgrade Failed; in that case, we won't return true (because "Degraded" will take precedence)
    54      progressiveUpgradeFailed = false
    55      if obj.status.conditions ~= nil then
    56        for i, condition in ipairs(obj.status.conditions) do
    57          if condition.type == "ProgressiveUpgradeSucceeded" and condition.status == "False" then
    58            progressiveUpgradeFailed = true
    59          end
    60        end
    61      end
    62  
    63      if progressiveUpgradeFailed == false then
    64        return true, "Update in progress"
    65      end
    66    end
    67  
    68    -- if the child is Progressing
    69    if obj.status.conditions ~= nil then
    70      for i, condition in ipairs(obj.status.conditions) do
    71        if condition.type == "ChildResourcesHealthy" and condition.status == "False" and condition.reason == "Progressing" then
    72          return true, "Child Progressing"
    73        end
    74      end
    75    end
    76  
    77    return false, ""
    78  end
    79  
    80  -- return true if healthy, along with the reason
    81  function isHealthy(obj)
    82    if obj.status == nil then 
    83      return false, ""
    84    end
    85  
    86    if obj.status.conditions ~= nil then
    87      for i, condition in ipairs(obj.status.conditions) do
    88        if condition.type == "ChildResourcesHealthy" and condition.status == "True" then
    89          return true, "Healthy"
    90        end
    91      end
    92    end
    93  end
    94  
    95  local hs = {}
    96  
    97  
    98  progressing, reason = isProgressing(obj)
    99  if progressing then
   100    hs.status = "Progressing"
   101    hs.message = reason
   102    return hs
   103  end
   104  
   105  degraded, reason = isDegraded(obj)
   106  if degraded then
   107    hs.status = "Degraded"
   108    hs.message = reason
   109    return hs
   110  end
   111  
   112  paused, reason = isPaused(obj)
   113  if paused then 
   114    hs.status = "Healthy"
   115    hs.message = reason
   116    return hs
   117  end
   118  
   119  healthy, reason = isHealthy(obj)
   120  if healthy then
   121    hs.status = "Healthy"
   122    hs.message = reason
   123    return hs
   124  end
   125  
   126  hs.status = "Unknown"
   127  hs.message = "Unknown MonoVertex status"
   128  return hs