From ada825957e6dcdf632aee4bad15d0e1e2aa1b7ec Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Thu, 11 Apr 2024 10:37:43 +0200 Subject: [PATCH] Instance status improvement --- pkg/instance.go | 5 ++++- pkg/instance_manager.go | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/instance.go b/pkg/instance.go index 36770b56..c59d136c 100644 --- a/pkg/instance.go +++ b/pkg/instance.go @@ -284,10 +284,13 @@ func (i Instance) HealthChecks() []string { continue } result := check.Check(i.manager.CheckContext().Value(checkContextKey{}).(CheckContext), i) - resultText := result.Text() + resultText := InstanceTrim(i, result.Text()) if resultText != "" { messages = append(messages, resultText) } + if !result.ok && check.Spec().Mandatory { + break + } } } return messages diff --git a/pkg/instance_manager.go b/pkg/instance_manager.go index dc88d188..87dc18b3 100644 --- a/pkg/instance_manager.go +++ b/pkg/instance_manager.go @@ -292,14 +292,21 @@ func (im *InstanceManager) Await(instances []Instance) error { return im.AwaitStarted(instances) } +func InstanceTrim(instance Instance, msgStr string) string { + return strings.Replace(msgStr, InstancePrefix(instance), "", -1) +} + func InstanceMsg(instance Instance, msg any) string { msgStr := fmt.Sprintf("%v", msg) - instanceIDPrefix := fmt.Sprintf("%s > ", instance.IDColor()) - msgStr = strings.Replace(msgStr, instanceIDPrefix, "", -1) - msgStr = instanceIDPrefix + msgStr + msgStr = InstanceTrim(instance, msgStr) + msgStr = InstancePrefix(instance) + msgStr return msgStr } +func InstancePrefix(instance Instance) string { + return fmt.Sprintf("%s > ", instance.IDColor()) +} + func InstancesMsg(instances []Instance, msg any) string { count := len(instances) switch count {