report healthcheck start errors

When starting a container consider healthcheck errors fatal. That way
user know when systemd-run failed to setup the timer to run the
healthcheck and we don't get into a state where the container is running
but not the healthcheck.

This also fixes the broken error reporting from the systemd-run exec, if
the binary could not be run the output was just empty leaving the users
with no idea what failed.

Fixes #25034

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2025-03-04 15:46:45 +01:00
parent 4ac061f383
commit 47a743bba2
4 changed files with 81 additions and 41 deletions

View File

@ -1144,7 +1144,7 @@ func (c *Container) init(ctx context.Context, retainRetries bool) error {
timer = c.config.StartupHealthCheckConfig.Interval.String()
}
if err := c.createTimer(timer, c.config.StartupHealthCheckConfig != nil); err != nil {
logrus.Error(err)
return fmt.Errorf("create healthcheck: %w", err)
}
}
@ -1333,10 +1333,10 @@ func (c *Container) start() error {
// to update status in such case.
if c.config.HealthCheckConfig != nil && !(len(c.config.HealthCheckConfig.Test) == 1 && c.config.HealthCheckConfig.Test[0] == "NONE") {
if err := c.updateHealthStatus(define.HealthCheckStarting); err != nil {
logrus.Error(err)
return fmt.Errorf("update healthcheck status: %w", err)
}
if err := c.startTimer(c.config.StartupHealthCheckConfig != nil); err != nil {
logrus.Error(err)
return fmt.Errorf("start healthcheck: %w", err)
}
}
@ -1627,7 +1627,7 @@ func (c *Container) unpause() error {
timer = c.config.StartupHealthCheckConfig.Interval.String()
}
if err := c.createTimer(timer, isStartupHealthCheck); err != nil {
return err
return fmt.Errorf("create healthcheck: %w", err)
}
}
@ -2895,7 +2895,9 @@ func (c *Container) resetHealthCheckTimers(noHealthCheck bool, changedTimer bool
if !isStartup {
if c.state.StartupHCPassed || c.config.StartupHealthCheckConfig == nil {
c.recreateHealthCheckTimer(context.Background(), false, false)
if err := c.recreateHealthCheckTimer(context.Background(), false, false); err != nil {
return err
}
}
return nil
}
@ -2908,7 +2910,9 @@ func (c *Container) resetHealthCheckTimers(noHealthCheck bool, changedTimer bool
return err
}
if wasEnabledHealthCheck {
c.recreateHealthCheckTimer(context.Background(), true, true)
if err := c.recreateHealthCheckTimer(context.Background(), true, true); err != nil {
return err
}
}
return nil
}