Skip to content

Commit 00ed517

Browse files
committed
Fix the healthcheck wait (bsc#1266012)
Running `podman healthcheck run` counts in the failure threshold. This means that the wait for the healthcheck running every second was hitting the threshold earlier than needed. The health is checked using podman inspect to extract the health status.
1 parent 48a0925 commit 00ed517

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

shared/connection.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,26 +307,34 @@ func (c *Connection) ExecScript(script string) ([]byte, error) {
307307
}
308308

309309
// Healthcheck runs healthcheck command inside the container.
310-
func (c *Connection) Healthcheck() ([]byte, error) {
310+
func (c *Connection) Healthcheck() error {
311311
if c.podName == "" {
312312
if _, err := c.GetPodName(); c.podName == "" {
313-
return nil, utils.Errorf(err, L("Healthcheck not executed"))
313+
return utils.Errorf(err, L("Healthcheck not executed"))
314314
}
315315
}
316316

317317
cmd, cmdErr := c.GetCommand()
318318
if cmdErr != nil {
319-
return nil, cmdErr
319+
return cmdErr
320320
}
321321

322322
if cmd == "host" {
323323
// Healthcheck not supported on host, always return nil
324-
return nil, nil
324+
return nil
325325
}
326326

327-
cmdArgs := []string{"healthcheck", "run", c.podName}
327+
cmdArgs := []string{"inspect", "--format", "{{ .State.Health.Status }}", c.podName}
328328

329-
return runner(cmd, cmdArgs...).Log(zerolog.DebugLevel).Spinner("").Exec()
329+
out, err := runner(cmd, cmdArgs...).Log(zerolog.DebugLevel).Spinner("").Exec()
330+
if err != nil {
331+
return err
332+
}
333+
outStr := strings.TrimSpace(string(out))
334+
if outStr != "healthy" && outStr != "running" {
335+
return errors.New(L("not healthy or running"))
336+
}
337+
return nil
330338
}
331339

332340
// WaitForContainer waits up to 10 sec for the container to appear.
@@ -380,7 +388,7 @@ func (c *Connection) WaitForHealthcheck() error {
380388
}
381389
// once here, container started at least once, clear startupTimeout
382390
startupTimeout = 0
383-
_, err := c.Healthcheck()
391+
err := c.Healthcheck()
384392
if err != nil {
385393
log.Debug().Err(err)
386394
time.Sleep(1 * time.Second)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Do not call podman healthcheck run to wait for pods to be ready
2+
(bsc#1266012)

0 commit comments

Comments
 (0)