Skip to content

Commit

Permalink
fix: improve health checks for kustomization, Pod & statefulset
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jun 24, 2024
1 parent cba9d80 commit 0bb80e4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions pkg/health/health_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions pkg/health/health_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/health/statusMap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Kustomization:
ready: true
message: true
reasons:
ReconciliationSucceeded:
health: healthy
Progressing:
status: Progressing
health: unknown
Expand Down Expand Up @@ -122,7 +124,6 @@ HelmRelease: &flux
onUnknown:
status: Reconciling
nonReady: true

Reconciling:
status: Reconciling
reasons:
Expand Down

0 comments on commit 0bb80e4

Please sign in to comment.