container_api: do not wait for healtchecks if stopped

do not wait for the healthcheck status to change if the container is
stopped.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2024-05-14 22:49:07 +02:00
parent b06c58b4a5
commit 35375e0af8

View File

@ -781,6 +781,14 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou
}
}
if len(wantedHealthStates) > 0 {
// even if we are interested only in the health check
// check that the container is still running to avoid
// waiting until the timeout expires.
state, err := c.State()
if err != nil {
trySend(-1, err)
return
}
status, err := c.HealthCheckStatus()
if err != nil {
trySend(-1, err)
@ -790,6 +798,10 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou
trySend(-1, nil)
return
}
if state != define.ContainerStateCreated && state != define.ContainerStateRunning && state != define.ContainerStatePaused {
trySend(-1, define.ErrCtrStopped)
return
}
}
select {
case <-ctx.Done():