github.com/argoproj/argo-cd/v3@v3.2.1/resource_customizations/core.spinkube.dev/SpinApp/health.lua (about)

     1  hs = {}
     2  
     3  -- Check if status exists
     4  if not obj.status then
     5    hs.status = "Progressing"
     6    hs.message = "Waiting for status to be available"
     7    return hs
     8  end
     9  
    10  -- Initialize variables for conditions
    11  local available = false
    12  local progressing = false
    13  local availableMessage = ""
    14  local progressingMessage = ""
    15  
    16  -- Check conditions - prioritize failure conditions first
    17  if obj.status.conditions then
    18    for _, condition in ipairs(obj.status.conditions) do
    19      if condition.type == "Progressing" then
    20        -- Check for timeout or failure in progressing condition first
    21        if condition.status == "False" and (condition.reason == "ProgressDeadlineExceeded" or string.find(string.lower(condition.message or ""), "timeout") or string.find(string.lower(condition.message or ""), "failed")) then
    22          hs.status = "Degraded"
    23          hs.message = condition.message or "Application deployment has failed"
    24          return hs
    25        end
    26        -- If progressing is true, mark it (any progressing=true condition wins)
    27        if condition.status == "True" then
    28          progressing = true
    29          progressingMessage = condition.message or "Application progress status"
    30        end
    31      elseif condition.type == "Available" then
    32        -- For available, we want all to be true, so any false condition wins
    33        if condition.status == "True" then
    34          available = true
    35          availableMessage = condition.message or "Application availability status"
    36        else
    37          available = false
    38          availableMessage = condition.message or "Application is not available"
    39        end
    40      end
    41    end
    42  end
    43  
    44  -- Check ready replicas if specified
    45  local readyReplicas = obj.status.readyReplicas or 0
    46  local desiredReplicas = obj.spec.replicas or 1
    47  
    48  -- Determine status based on conditions
    49  if not available then
    50    hs.status = "Degraded"
    51    hs.message = availableMessage or "Application is not available"
    52    return hs
    53  end
    54  
    55  if readyReplicas < desiredReplicas then
    56    hs.status = "Progressing"
    57    hs.message = string.format("Waiting for replicas to be ready (%d/%d)", readyReplicas, desiredReplicas)
    58    return hs
    59  end
    60  
    61  if progressing then
    62    hs.status = "Progressing"
    63    hs.message = progressingMessage or "Application is still progressing"
    64    return hs
    65  end
    66  
    67  -- All checks passed
    68  hs.status = "Healthy"
    69  hs.message = string.format("Application is healthy with %d/%d replicas ready", readyReplicas, desiredReplicas)
    70  
    71  return hs