Skip to content

kuberhealthy/go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example Go Client

This repository contains a minimal Go example program under cmd/example that reports its status back to Kuberhealthy. The example uses the official checkclient package from the Kuberhealthy project, which you can import into your own Go checks.

Using the Kuberhealthy check client

Import the client and report success or failure:

import checkclient "github.com/kuberhealthy/kuberhealthy/v3/pkg/checkclient"

func runCheck() error {
    // do some work...
    if problem {
        return checkclient.ReportFailure([]string{"something went wrong"})
    }
    return checkclient.ReportSuccess()
}

The client expects the KH_REPORTING_URL and KH_RUN_UUID environment variables, which are provided by Kuberhealthy when the check runs.

Example program

cmd/example/main.go demonstrates using checkclient to report either success or failure based on the FAIL environment variable.

Building

make build
make docker-build IMAGE=yourrepo/example-check:tag
make docker-push IMAGE=yourrepo/example-check:tag

Deploying

Create a KHCheck that references the image you built:

apiVersion: kuberhealthy.github.io/v2
kind: KHCheck
metadata:
  name: example-check
spec:
  runInterval: 1m
  timeout: 30s
  podSpec:
    containers:
    - name: example
      image: yourrepo/example-check:tag
      env:
      - name: FAIL
        value: "true"

Apply the resource to any cluster running Kuberhealthy:

kubectl apply -f khcheck.yaml

About

Client example for go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published