Merge pull request #3476 from ashley-cui/remotehealthcheck

Implement healthcheck for remote client
This commit is contained in:
OpenShift Merge Robot
2019-08-19 20:17:31 +02:00
committed by GitHub
8 changed files with 31 additions and 19 deletions

8
API.md
View File

@ -87,6 +87,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
[func GetVolumes(args: []string, all: bool) Volume](#GetVolumes)
[func HealthCheckRun(nameOrID: string) string](#HealthCheckRun)
[func HistoryImage(name: string) ImageHistory](#HistoryImage)
[func ImageExists(name: string) int](#ImageExists)
@ -681,6 +683,12 @@ GetVersion returns version and build information of the podman service
method GetVolumes(args: [[]string](#[]string), all: [bool](https://godoc.org/builtin#bool)) [Volume](#Volume)</div>
GetVolumes gets slice of the volumes on a remote host
### <a name="HealthCheckRun"></a>func HealthCheckRun
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method HealthCheckRun(nameOrID: [string](https://godoc.org/builtin#string)) [string](https://godoc.org/builtin#string)</div>
HealthCheckRun executes defined container's healthcheck command
and returns the container's health status.
### <a name="HistoryImage"></a>func HistoryImage
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">

View File

@ -71,10 +71,3 @@ func getSystemSubCommands() []*cobra.Command {
_migrateCommand,
}
}
// Commands that the local client implements
func getHealthcheckSubCommands() []*cobra.Command {
return []*cobra.Command{
_healthcheckrunCommand,
}
}

View File

@ -47,8 +47,3 @@ func getTrustSubCommands() []*cobra.Command {
func getSystemSubCommands() []*cobra.Command {
return []*cobra.Command{}
}
// Commands that the remoteclient implements
func getHealthcheckSubCommands() []*cobra.Command {
return []*cobra.Command{}
}

View File

@ -16,11 +16,12 @@ var healthcheckCommand = cliconfig.PodmanCommand{
}
// Commands that are universally implemented
var healthcheckCommands []*cobra.Command
var healthcheckCommands = []*cobra.Command{
_healthcheckrunCommand,
}
func init() {
healthcheckCommand.AddCommand(healthcheckCommands...)
healthcheckCommand.AddCommand(getHealthcheckSubCommands()...)
healthcheckCommand.SetUsageTemplate(UsageTemplate())
rootCmd.AddCommand(healthcheckCommand.Command)
}

View File

@ -544,6 +544,10 @@ method GetContainersByStatus(status: []string) -> (containerS: []Container)
method Top (nameOrID: string, descriptors: []string) -> (top: []string)
# HealthCheckRun executes defined container's healthcheck command
# and returns the container's health status.
method HealthCheckRun (nameOrID: string) -> (healthCheckStatus: string)
# GetContainer returns information about a single container. If a container
# with the given id doesn't exist, a [ContainerNotFound](#ContainerNotFound)
# error will be returned. See also [ListContainers](ListContainers) and

View File

@ -21,7 +21,7 @@ import (
"github.com/containers/image/types"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/remoteclientconfig"
"github.com/containers/libpod/cmd/podman/varlink"
iopodman "github.com/containers/libpod/cmd/podman/varlink"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/events"
@ -812,7 +812,7 @@ func IsImageNotFound(err error) bool {
// HealthCheck executes a container's healthcheck over a varlink connection
func (r *LocalRuntime) HealthCheck(c *cliconfig.HealthCheckValues) (string, error) {
return "", define.ErrNotImplemented
return iopodman.HealthCheckRun().Call(r.Conn, c.InputArgs[0])
}
// Events monitors libpod/podman events over a varlink connection

View File

@ -14,7 +14,7 @@ import (
"time"
"github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/cmd/podman/varlink"
iopodman "github.com/containers/libpod/cmd/podman/varlink"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/logs"
@ -864,3 +864,16 @@ func (i *LibpodAPI) ExecContainer(call iopodman.VarlinkCall, opts iopodman.ExecO
return ecErr.Error
}
//HealthCheckRun executes defined container's healthcheck command and returns the container's health status.
func (i *LibpodAPI) HealthCheckRun(call iopodman.VarlinkCall, nameOrID string) error {
hcStatus, err := i.Runtime.HealthCheck(nameOrID)
if err != nil && hcStatus != libpod.HealthCheckFailure {
return call.ReplyErrorOccurred(err.Error())
}
status := libpod.HealthCheckUnhealthy
if hcStatus == libpod.HealthCheckSuccess {
status = libpod.HealthCheckHealthy
}
return call.ReplyHealthCheckRun(status)
}

View File

@ -1,5 +1,3 @@
// +build !remoteclient
package integration
import (