github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/api/handlers/libpod/healthcheck.go (about)

     1  package libpod
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/containers/podman/v2/libpod"
     7  	"github.com/containers/podman/v2/libpod/define"
     8  	"github.com/containers/podman/v2/pkg/api/handlers/utils"
     9  )
    10  
    11  func RunHealthCheck(w http.ResponseWriter, r *http.Request) {
    12  	runtime := r.Context().Value("runtime").(*libpod.Runtime)
    13  	name := utils.GetName(r)
    14  	status, err := runtime.HealthCheck(name)
    15  	if err != nil {
    16  		if status == define.HealthCheckContainerNotFound {
    17  			utils.ContainerNotFound(w, name, err)
    18  			return
    19  		}
    20  		if status == define.HealthCheckNotDefined {
    21  			utils.Error(w, "no healthcheck defined", http.StatusConflict, err)
    22  			return
    23  		}
    24  		if status == define.HealthCheckContainerStopped {
    25  			utils.Error(w, "container not running", http.StatusConflict, err)
    26  			return
    27  		}
    28  		utils.InternalServerError(w, err)
    29  		return
    30  	}
    31  	hcStatus := define.HealthCheckUnhealthy
    32  	if status == define.HealthCheckSuccess {
    33  		hcStatus = define.HealthCheckHealthy
    34  	}
    35  	report := define.HealthCheckResults{
    36  		Status: hcStatus,
    37  	}
    38  	utils.WriteResponse(w, http.StatusOK, report)
    39  }