Documentation
¶
Index ¶
- type Checker
- func All(checkers ...Checker) Checker
- func Any(checkers ...Checker) Checker
- func CheckCommandStatus(ctx context.Context, cmd string, args ...string) Checker
- func CheckContainerStarted(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string) Checker
- func CheckDirectoryExists(path string) Checker
- func CheckK8sPods(ctx context.Context, client *kubernetes.Clientset, label string, ...) Checker
- func CheckNetwork(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, ...) Checker
- func CheckRedisPort(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client) Checker
- func DialableChecker(protocol string, address string) Checker
- func Not(ckr Checker) Checker
- type Fixer
- func And(fixers ...Fixer) Fixer
- func BuildImage(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, ...) Fixer
- func CreateDirectory(path string) Fixer
- func CreateNetwork(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, ...) Fixer
- func NotImplemented() Fixer
- func Or(fixers ...Fixer) Fixer
- func RequiresManualFixing() Fixer
- func StartCommand(ctx context.Context, cmd string, args ...string) Fixer
- func StartContainer(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, ...) Fixer
- type Helper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Checker ¶
Checker is a function that checks whether a precondition is met. It returns whether the check succeeded, an optional message to present to the user, and error in case the check logic itself failed.
(true, *, nil) => HealthcheckStatusOK (false, *, nil) => HealthcheckStatusFailed (false, *, not-nil) => HealthcheckStatusAborted checker doesn't run => HealthcheckStatusOmitted (e.g. dependent checks where the upstream failed)
func All ¶
All returns a Checker that succeeds when all provided Checkers succeed. If a Checker fails, it short-circuits and returns the first failure.
func Any ¶
Any returns a Checker that succeeds if any of the provided Checkers succeed. If none do, it fails.
func CheckCommandStatus ¶
CheckCommandStatus returns a checker which executes a command and returns successfully or unsuccessfully depending on the exit status of the command.
func CheckContainerStarted ¶
func CheckContainerStarted(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string) Checker
CheckContainerStarted returns a Checker that succeeds if a container is started, and fails otherwise.
func CheckDirectoryExists ¶
CheckDirectoryExists returns a Checker that checks whether the specified directory exists. It succeeds if the directory exists, and fails if the Go runtime returns a ErrNotExist error. All other errors are propagated back, which presumably will mark this check as aborted.
func CheckK8sPods ¶
func CheckK8sPods(ctx context.Context, client *kubernetes.Clientset, label string, namespace string, count int) Checker
CheckK8sPods returns a checker which verifies the number of pods found matches the number expected. If Listing the pods returns an error, the error is returned. The boolean value returned by the check follows whether the number of pods observed in the list matches the expected count.
func CheckNetwork ¶
func CheckNetwork(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, networkID string) Checker
CheckNetwork returns a Checker that succeeds if the specified network exists, and fails otherwise.
func CheckRedisPort ¶ added in v0.5.3
CheckRedisPort returns a checker which verifies if the default port of redis (6379) is already binded on localhost. If it is, it fails. If not, it succeeds.
func DialableChecker ¶
DialableChecker returns a Checker that checks whether a remote endpoint is dialable. For TCP sockets, a failure could mean the network is unreachable, or that the remote TCP socket is closed. For UDP sockets, being connectionless, may return a false positive even if there is no listening process, but at least it will try to find a route to the host.
func Not ¶
Not negates a Checker. To make it clear to the user that the check is negated, the message is re-formatted using "NOT(<msg>)" notation.
Any error encountered when the check is executed gets included in the message value.
This is useful if there is a checker which does exactly the opposite of what you want to check for i.e. you want to check that a directory does NOT exist, etc. or you want to check for combinations using Any() or All() with some negated predicates.
type Fixer ¶
Fixer is a function that will be called to attempt to fix a failing check. It returns an optional message to present to the user, and error in case the fix failed.
func And ¶
And returns a Fixer that executes all fixes sequentially, short-circuiting at the first error.
func BuildImage ¶
func BuildImage(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, opts *docker.BuildImageOpts) Fixer
BuildImage returns a Fixer that builds the provided image if it doesn't exist yet.
func CreateDirectory ¶
CreateDirectory returns a Fixer that creates the specified directory and any parent directories as appropriate.
func CreateNetwork ¶
func CreateNetwork(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, networkID string, netcfg network.IPAMConfig) Fixer
CreateNetwork returns a Fixer that creates a Docker bridge network with supplied ID and characteristics.
func NotImplemented ¶
func NotImplemented() Fixer
NotImplemented is a placeholder Fixer which always returns successfully.
func Or ¶
Or returns a Fixer that short-circuits on the first success, or errors if all fixes failed.
func RequiresManualFixing ¶ added in v0.5.3
func RequiresManualFixing() Fixer
RequiresManualFixing is a placeholder Fixer which always returns unsuccessfully.
func StartCommand ¶
StartCommand returns a Fixer that starts the given process, under the supplied context, via os/exec.CommandContext.
func StartContainer ¶
func StartContainer(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, opts *docker.EnsureContainerOpts) Fixer
StartContainer returns a Fixer that starts the specified container if it exists, potentially acquiring the image first via the supplied image strategy, if the image itself is absent.
type Helper ¶
Helper is a utility that facilitates the execution of healthchecks.
Healthchecks are registered via the Enlist() method, which takes a name, a Checker, and a Fixer function. Common Checker and Fixer functions can be found in this package.
To run the healthchecks and obtain an api.HealthcheckReport, call RunChecks.
Healthchecks are run sequentially, in the same order they were listed.
For each item, the Checker runs first. If it results in a "failed" status, and an associated Fixer is registered, we run the Fixer, if and only if "fix" mode is requested when calling RunChecks.