This repository provides a minimal library and example check for reporting results back to Kuberhealthy.
The reusable client library now lives in the kuberhealthy-client subcrate and can be imported into your own Rust programs. The repository root contains the kuberhealthy-example binary, which demonstrates how to use the client in a check container.
Add the crate to your Cargo.toml:
[dependencies]
kuberhealthy-client = "0.1"Example usage:
use kuberhealthy_client::KuberhealthyClient;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = KuberhealthyClient::from_env()?;
// Perform check logic here...
client.report_success()?;
Ok(())
}The client reads the KH_REPORTING_URL and KH_RUN_UUID environment variables provided to every check pod and posts a JSON report with the kh-run-uuid header.
Run without arguments to report success or with --fail to report a failure.
KH_REPORTING_URL="http://localhost" KH_RUN_UUID="test" cargo run --bin kuberhealthy-example
KH_REPORTING_URL="http://localhost" KH_RUN_UUID="test" cargo run --bin kuberhealthy-example -- --failReplace the placeholder logic in src/main.rs with your own check logic and then build and publish the container image:
make build # compile the binary
IMAGE=myrepo/kuberhealthy-rust-example:latest make docker-build
IMAGE=myrepo/kuberhealthy-rust-example:latest make pushAfter the image is pushed, reference it from a KuberhealthyCheck resource:
apiVersion: kuberhealthy.github.io/v2
kind: KuberhealthyCheck
metadata:
name: rust-example
spec:
runInterval: 30s
timeout: 2m
podSpec:
containers:
- name: main
image: myrepo/kuberhealthy-rust-example:latest
imagePullPolicy: IfNotPresentApply the resource to any cluster where Kuberhealthy is running:
kubectl apply -f khcheck.yamlA GitHub Actions workflow builds the example container on every change. When a release is published, another workflow publishes the kuberhealthy-client crate from the subdirectory and pushes the example container image to the GitHub Container Registry.