Files
podman/pkg/api/handlers/libpod/healthcheck.go
Jan Rodák 511d912685 Add stopped status for HealthCheck
If the container is stopped and the ongoing HealthCheck has no chance to complete the check is evaluated as stopped.

Fixes: https://issues.redhat.com/browse/RUN-2520
Fixes: https://github.com/containers/podman/issues/25276

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2025-03-03 17:09:30 +01:00

39 lines
974 B
Go

//go:build !remote
package libpod
import (
"net/http"
"github.com/containers/podman/v5/libpod"
"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/api/handlers/utils"
api "github.com/containers/podman/v5/pkg/api/types"
)
func RunHealthCheck(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
name := utils.GetName(r)
status, err := runtime.HealthCheck(r.Context(), name)
if err != nil {
if status == define.HealthCheckContainerNotFound {
utils.ContainerNotFound(w, name, err)
return
}
if status == define.HealthCheckNotDefined {
utils.Error(w, http.StatusConflict, err)
return
}
if status == define.HealthCheckContainerStopped {
utils.Error(w, http.StatusConflict, err)
return
}
utils.InternalServerError(w, err)
return
}
report := define.HealthCheckResults{
Status: status.String(),
}
utils.WriteResponse(w, http.StatusOK, report)
}