Skip to content

Commit

Permalink
Merge pull request #476 from gWOLF3/master
Browse files Browse the repository at this point in the history
add kuberhealthy-client npm package to readme
  • Loading branch information
jonnydawg committed May 15, 2020
2 parents 387bc30 + 5a2866e commit 3426907
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions docs/EXTERNAL_CHECK_CREATION.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,65 @@
## Creating Your Own `khcheck`

#### Creating your own `khcheck` client is simple! :)

### Using Go

Creating your own `khcheck` is very easy. If you are using Go, we have an easy to use client package at [github.com/Comcast/kuberhealthy/v2/pkg/checks/external/checkclient](https://godoc.org/github.com/Comcast/kuberhealthy/v2/pkg/checks/external/checkclient).
If you are using Go, we have an easy to use client package: [found here](https://godoc.org/github.com/Comcast/kuberhealthy/v2/pkg/checks/external/checkclient).

example code:

```go
package main

import (
"github.com/Comcast/kuberhealthy/v2/pkg/checks/external/checkclient"
)

<img src="../images/example check.png">
func main() {
ok := doCheckStuff()
if !ok {
checkclient.ReportFailure([]string{"Test has failed!"})
return
}
checkclient.ReportSuccess()
}

```

An example check with working Dockerfile is available to use as an example [here](../cmd/test-external-check/main.go).

### Using JavaScript

If you would like to write a check in JavaScript, there is a client for external checks found [here](../clients/js/).
#### Reference Sample:

If you would like to write a check in JavaScript, there is a sample client for external checks found [here](../clients/js/).

There is also an [example check](../clients/js/example) in the under the same folder with a Dockerfile for reference.
Please see the [example check](../clients/js/example) under the same folder with a Dockerfile for reference.

#### NPM:

The kuberhealthy [NPM package](https://www.npmjs.com/package/kuberhealthy) is conformant with the reference sample syntax but also supports async/await as well as arbitrary host and port.

- more info: [kuberhealthy-client](https://github.com/gWOLF3/kuberhealthy-client)
- get started: `npm i --save kuberhealthy`


example code:
```javascript
const kh = require('kuberhealthy')

const report = async () => {
let ok = await doCheckStuff()
if (ok) {
await kh.ReportSuccess()
} else {
await kh.ReportFailure()
}

report()
```
> _NOTE: KH_REPORTING_URL must be set in your env. This is usually done automatically if running as 'khcheck' on kubernetes._
For more information on the external client for JavaScript go [here](../clients/js/README.md).
### Using Another Language
Expand All @@ -34,7 +79,7 @@ Your check only needs to do a few things:
}
```
Never send `"OK": true` if `Errors` has values or you will be given a `400` return code.
> Never send `"OK": true` if `Errors` has values or you will be given a `400` return code.
Simply build your program into a container, `docker push` it to somewhere your cluster has access and craft a `khcheck` resource to enable it in your cluster where Kuberhealthy is installed.
Expand Down

0 comments on commit 3426907

Please sign in to comment.