github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/api/handlers/libpod/healthcheck.go (about)

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