diff options
author | Brent Baude <bbaude@redhat.com> | 2020-02-25 13:51:49 -0600 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2020-03-13 07:43:12 -0500 |
commit | 2099643aa2929e8d394c8b0fb584ad90075ad0b5 (patch) | |
tree | a40d66583f16581bcfd0ed2094acf478d151e442 /pkg/api | |
parent | c9f148fb154ca45081e3ebfc0c14fa9ee995780d (diff) | |
download | podman-2099643aa2929e8d394c8b0fb584ad90075ad0b5.tar.gz podman-2099643aa2929e8d394c8b0fb584ad90075ad0b5.tar.bz2 podman-2099643aa2929e8d394c8b0fb584ad90075ad0b5.zip |
add apiv2 healthcheck code
reworking binding and endpoint to actually work. added documentation in swagger for and various return code possibilities. add a good start on tests though we need some other container functions not yet implemented for that.
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/api')
-rw-r--r-- | pkg/api/handlers/libpod/healthcheck.go | 24 | ||||
-rw-r--r-- | pkg/api/server/register_healthcheck.go | 25 | ||||
-rw-r--r-- | pkg/api/server/swagger.go | 9 |
3 files changed, 56 insertions, 2 deletions
diff --git a/pkg/api/handlers/libpod/healthcheck.go b/pkg/api/handlers/libpod/healthcheck.go index 6c74500b9..6eb2ab0e3 100644 --- a/pkg/api/handlers/libpod/healthcheck.go +++ b/pkg/api/handlers/libpod/healthcheck.go @@ -14,8 +14,30 @@ func RunHealthCheck(w http.ResponseWriter, r *http.Request) { if err != nil { if status == libpod.HealthCheckContainerNotFound { utils.ContainerNotFound(w, name, err) + return } + if status == libpod.HealthCheckNotDefined { + utils.Error(w, "no healthcheck defined", http.StatusConflict, err) + return + } + if status == libpod.HealthCheckContainerStopped { + utils.Error(w, "container not running", http.StatusConflict, err) + return + } + utils.InternalServerError(w, err) + return + } + ctr, err := runtime.LookupContainer(name) + if err != nil { utils.InternalServerError(w, err) + return } - utils.WriteResponse(w, http.StatusOK, status) + + hcLog, err := ctr.GetHealthCheckLog() + if err != nil { + utils.InternalServerError(w, err) + return + } + + utils.WriteResponse(w, http.StatusOK, hcLog) } diff --git a/pkg/api/server/register_healthcheck.go b/pkg/api/server/register_healthcheck.go index 5466e2905..69aa5bbfb 100644 --- a/pkg/api/server/register_healthcheck.go +++ b/pkg/api/server/register_healthcheck.go @@ -8,6 +8,29 @@ import ( ) func (s *APIServer) registerHealthCheckHandlers(r *mux.Router) error { - r.Handle(VersionedPath("/libpod/containers/{name}/runhealthcheck"), s.APIHandler(libpod.RunHealthCheck)).Methods(http.MethodGet) + // swagger:operation GET /libpod/containers/{name:.*}/healthcheck libpod libpodRunHealthCheck + // --- + // tags: + // - containers + // summary: Run a container's healthcheck + // description: Execute the defined healthcheck and return information about the results + // parameters: + // - in: path + // name: name:.* + // type: string + // required: true + // description: the name or ID of the container + // produces: + // - application/json + // responses: + // 200: + // $ref: "#/responses/HealthcheckRun" + // 404: + // $ref: "#/responses/NoSuchContainer" + // 409: + // description: container has no healthcheck or is not running + // 500: + // $ref: '#/responses/InternalError' + r.Handle(VersionedPath("/libpod/containers/{name:.*}/healthcheck"), s.APIHandler(libpod.RunHealthCheck)).Methods(http.MethodGet) return nil } diff --git a/pkg/api/server/swagger.go b/pkg/api/server/swagger.go index 011196e5a..e3c991d6d 100644 --- a/pkg/api/server/swagger.go +++ b/pkg/api/server/swagger.go @@ -156,3 +156,12 @@ type swagVolumeListResponse struct { // in:body Body []libpod.Volume } + +// Healthcheck +// swagger:response HealthcheckRun +type swagHealthCheckRunResponse struct { + // in:body + Body struct { + libpod.HealthCheckResults + } +} |