monitoring: surface CrashLoopBackOff pods as degraded on the frontend
Some checks are pending
Build and Test / Secret Scan (push) Waiting to run
Build and Test / Frontend & Backend (push) Waiting to run

monitorFrontendStatus's "pod" branch was re-deriving status from
Kubernetes.PodPhase alone, so a CrashLoopBackOff pod (Phase=Running
with unready containers) was reported as "running" even though
statusFromKubernetesPod had already classified it as StatusWarning.

Drop the unconditional phase=running -> "running" mapping and fall
through to the unified-status switch, which surfaces StatusWarning as
"degraded". Phase-based mappings for pending/unknown/succeeded/failed
are kept since they still cover edge cases where the unified status
is StatusOnline but phase carries useful information.

Adds two regression cases in TestMonitorFrontendAndMetricHelpers:
- pod warning running degraded (CrashLoopBackOff)
- pod online running running (healthy baseline)
This commit is contained in:
rcourtman 2026-05-19 22:37:55 +01:00
parent 8ae422c243
commit a191f2ab2b
2 changed files with 27 additions and 2 deletions

View file

@ -437,6 +437,29 @@ func TestMonitorFrontendAndMetricHelpers(t *testing.T) {
},
want: "stopped",
},
{
// CrashLoopBackOff: phase stays "Running" but containers are
// unready, so statusFromKubernetesPod returns StatusWarning.
// The frontend mapping must surface that as "degraded" rather
// than reporting the pod as healthy on the strength of phase
// alone.
name: "pod warning running degraded",
resourceType: "pod",
resource: unifiedresources.Resource{
Status: unifiedresources.StatusWarning,
Kubernetes: &unifiedresources.K8sData{PodPhase: "running"},
},
want: "degraded",
},
{
name: "pod online running running",
resourceType: "pod",
resource: unifiedresources.Resource{
Status: unifiedresources.StatusOnline,
Kubernetes: &unifiedresources.K8sData{PodPhase: "running"},
},
want: "running",
},
{
name: "workload online running fallback",
resourceType: "system-container",

View file

@ -5667,13 +5667,15 @@ func monitorFrontendStatus(resource unifiedresources.Resource, resourceType stri
if resource.Kubernetes != nil {
phase := strings.ToLower(strings.TrimSpace(resource.Kubernetes.PodPhase))
switch phase {
case "running":
return "running"
case "pending", "unknown":
return "degraded"
case "succeeded", "failed":
return "stopped"
}
// Phase=Running is not enough — a pod can have Phase=Running with
// CrashLoopBackOff containers, which statusFromKubernetesPod
// correctly classifies as StatusWarning. Fall through to the
// unified-status mapping below so that surfaces as "degraded".
}
}