From 0bb80e4dfa57ff0ae4bbe95997f94a0bdb76ec1d Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Mon, 24 Jun 2024 11:38:29 +0545 Subject: [PATCH] fix: improve health checks for kustomization, Pod & statefulset --- pkg/health/health.go | 1 + pkg/health/health_pod.go | 10 ++++++++++ pkg/health/health_statefulset.go | 11 +++++++++++ pkg/health/statusMap.yaml | 3 ++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/health/health.go b/pkg/health/health.go index b6fd8e3..79c8a41 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -48,6 +48,7 @@ const ( HealthStatusScaling HealthStatusCode = "Scaling" HealthStatusRestart HealthStatusCode = "Restarting" HealthStatusStarting HealthStatusCode = "Starting" + HealthStatusUnschedulable HealthStatusCode = "Unschedulable" HealthStatusScalingUp HealthStatusCode = "Scaling Up" HealthStatusScaledToZero HealthStatusCode = "Scaled to Zero" diff --git a/pkg/health/health_pod.go b/pkg/health/health_pod.go index 31c1e7d..b559372 100644 --- a/pkg/health/health_pod.go +++ b/pkg/health/health_pod.go @@ -107,6 +107,16 @@ func getCorev1PodHealth(pod *corev1.Pod) (*HealthStatus, error) { } } + for _, ctrStatus := range pod.Status.Conditions { + if ctrStatus.Reason == "Unschedulable" { + return &HealthStatus{ + Health: HealthUnhealthy, + Status: HealthStatusUnschedulable, + Message: ctrStatus.Message, + }, nil + } + } + return &HealthStatus{ Health: HealthUnknown, Status: HealthStatusPending, diff --git a/pkg/health/health_statefulset.go b/pkg/health/health_statefulset.go index 91bf047..890339d 100644 --- a/pkg/health/health_statefulset.go +++ b/pkg/health/health_statefulset.go @@ -24,6 +24,17 @@ func getStatefulSetHealth(obj *unstructured.Unstructured) (*HealthStatus, error) } func getAppsv1StatefulSetHealth(sts *appsv1.StatefulSet) (*HealthStatus, error) { + replicas := int32(0) + if sts.Spec.Replicas != nil { + replicas = *sts.Spec.Replicas + } + + if replicas == 0 && sts.Status.Replicas == 0 { + return &HealthStatus{ + Status: HealthStatusScaledToZero, + Health: HealthUnknown, + }, nil + } health := HealthHealthy if sts.Status.ReadyReplicas == 0 { diff --git a/pkg/health/statusMap.yaml b/pkg/health/statusMap.yaml index 6034d96..298931a 100644 --- a/pkg/health/statusMap.yaml +++ b/pkg/health/statusMap.yaml @@ -87,6 +87,8 @@ Kustomization: ready: true message: true reasons: + ReconciliationSucceeded: + health: healthy Progressing: status: Progressing health: unknown @@ -122,7 +124,6 @@ HelmRelease: &flux onUnknown: status: Reconciling nonReady: true - Reconciling: status: Reconciling reasons: