Skip to content

Commit

Permalink
Merge pull request #221 from wttech/instance-check-imprs
Browse files Browse the repository at this point in the history
Instance check improvements
  • Loading branch information
krystian-panek-vmltech authored Dec 1, 2023
2 parents 5f212b9 + 3305990 commit 7f70679
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
15 changes: 13 additions & 2 deletions pkg/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ func (c *CheckResult) Err() error {
return c.err
}

func (c *CheckResult) Text() string {
if c.message != "" && c.err != nil {
return fmt.Sprintf("%s: %s", c.message, c.err)
}
if c.message != "" {
return c.message
}
if c.err != nil {
return fmt.Sprintf("%s", c.err)
}
return ""
}

type Checker interface {
Check(ctx CheckContext, instance Instance) CheckResult
Spec() CheckSpec
Expand Down Expand Up @@ -282,7 +295,6 @@ func (c InstallerChecker) Check(_ CheckContext, instance Instance) CheckResult {
return CheckResult{
ok: false,
message: fmt.Sprintf("installer active (%d)", state.ActiveResources()),
err: err,
}
}
}
Expand All @@ -299,7 +311,6 @@ func (c InstallerChecker) Check(_ CheckContext, instance Instance) CheckResult {
return CheckResult{
ok: false,
message: fmt.Sprintf("installer paused (%d)", pauseCount),
err: err,
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,17 @@ func (i Instance) HealthChecks() []string {
i.manager.CheckOpts.BundleStable,
i.manager.CheckOpts.EventStable,
i.manager.CheckOpts.Installer,
i.manager.CheckOpts.LoginPage,
i.manager.CheckOpts.ComponentStable,
}
for _, check := range checks {
if check.Spec().Skip {
continue
}
result := check.Check(i.manager.CheckContext().Value(checkContextKey{}).(CheckContext), i)
if result.message != "" {
messages = append(messages, result.message)
} else if result.err != nil {
messages = append(messages, fmt.Sprintf("%s", result.err))
resultText := result.Text()
if resultText != "" {
messages = append(messages, resultText)
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/instance_manager_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@ func (im *InstanceManager) checkOne(ctx context.Context, i Instance, checks []Ch
if result.abort {
log.Fatal(InstanceMsg(i, result.message))
}
if result.err != nil {
log.Info(InstanceMsg(i, result.err))
} else if len(result.message) > 0 {
log.Info(InstanceMsg(i, result.message))
resultText := result.Text()
if resultText != "" {
if result.ok {
log.Info(InstanceMsg(i, resultText))
} else {
log.Warn(InstanceMsg(i, resultText))
}
}
if !result.ok && check.Spec().Mandatory {
break
Expand Down

0 comments on commit 7f70679

Please sign in to comment.