From c7868779f3cabe984716428f371d02b3b08440e9 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Mon, 5 Aug 2024 14:08:31 +0545 Subject: [PATCH] feat: generic health getter by config type --- pkg/health/health.go | 8 ++++++++ pkg/health/health_deployment.go | 4 ++-- pkg/health/utils.go | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/health/health.go b/pkg/health/health.go index 5c125b6..2a1be3c 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -98,6 +98,14 @@ func IsWorse(current, new HealthStatusCode) bool { return newIndex > currentIndex } +func GetHealthByConfigType(configType string, obj map[string]any) HealthStatus { + if strings.HasPrefix(configType, "Mongo::") { + return GetMongoHealth(obj) + } + + return HealthStatus{} +} + // GetResourceHealth returns the health of a k8s resource func GetResourceHealth(obj *unstructured.Unstructured, healthOverride HealthOverride) (health *HealthStatus, err error) { if healthCheck := GetHealthCheckFunc(obj.GroupVersionKind()); healthCheck != nil { diff --git a/pkg/health/health_deployment.go b/pkg/health/health_deployment.go index 80fabd2..ad0fb96 100644 --- a/pkg/health/health_deployment.go +++ b/pkg/health/health_deployment.go @@ -44,9 +44,9 @@ func getAppsv1DeploymentHealth(deployment *appsv1.Deployment, obj *unstructured. } if deployment.Status.ReadyReplicas == replicas { - status.PreppendMessage("%d pods ready", deployment.Status.ReadyReplicas) + status.PrependMessage("%d pods ready", deployment.Status.ReadyReplicas) } else { - status.PreppendMessage("%d of %d pods ready", deployment.Status.ReadyReplicas, replicas) + status.PrependMessage("%d of %d pods ready", deployment.Status.ReadyReplicas, replicas) } if deployment.Spec.Paused { diff --git a/pkg/health/utils.go b/pkg/health/utils.go index f7830d6..8920cb2 100644 --- a/pkg/health/utils.go +++ b/pkg/health/utils.go @@ -49,7 +49,7 @@ func (hs *HealthStatus) AppendMessage(msg string, args ...interface{}) { hs.Message += fmt.Sprintf(msg, args...) } -func (hs *HealthStatus) PreppendMessage(msg string, args ...interface{}) { +func (hs *HealthStatus) PrependMessage(msg string, args ...interface{}) { if msg == "" { return }