Skip to content

Commit

Permalink
feat: generic health getter by config type
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Aug 5, 2024
1 parent 67b9e2a commit c786877
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pkg/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/health/health_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/health/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c786877

Please sign in to comment.