Skip to content

kuberhealthy/java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Client and Example

This repository provides a minimal Java client for reporting check results to Kuberhealthy and an example check that uses it. The ExampleCheck program reads the KH_REPORTING_URL and KH_RUN_UUID environment variables that Kuberhealthy injects into checker pods and posts a JSON status report.

Using the client library

Applications can depend on the client published to GitHub Packages:

<dependency>
  <groupId>io.kuberhealthy</groupId>
  <artifactId>kuberhealthy-client</artifactId>
  <version>0.1.0-SNAPSHOT</version>
</dependency>

Add https://maven.pkg.github.com/OWNER/REPO as a Maven repository and authenticate with a GitHub token that has permission to read packages.

Within your code, create a KuberhealthyClient and call report:

import io.kuberhealthy.client.KuberhealthyClient;

KuberhealthyClient client = new KuberhealthyClient(url, uuid);
client.report(true, "");

Extending the example check

Add your own logic inside ExampleCheck.java before reporting the result. The file defaults to reporting success and includes commented-out lines that show how to report a failure:

// ok = false;
// error = "something went wrong";

Call report with ok=true when the check succeeds or ok=false with an error message when it fails. Non-200 responses from Kuberhealthy cause the program to exit with an error so rejected payloads surface immediately.

Building and pushing the container

Build and push the container image:

make build IMAGE=registry.example.com/java-example:latest
make push IMAGE=registry.example.com/java-example:latest

Deploying

Create a KuberhealthyCheck that uses the pushed image:

apiVersion: khcheck.kuberhealthy.io/v1
kind: KuberhealthyCheck
metadata:
  name: java-example
spec:
  runInterval: 15m
  timeout: 5m
  podSpec:
    containers:
    - name: checker
      image: registry.example.com/java-example:latest
      imagePullPolicy: Always

Apply the manifest to a cluster running Kuberhealthy:

kubectl apply -f khcheck.yaml

The pod will receive the required KH_REPORTING_URL and KH_RUN_UUID variables and the check will report success or failure back to Kuberhealthy.

About

Java client for kuberhealthy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published