Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add kuberhealthy-client npm package to readme #476

Merged
merged 2 commits into from
May 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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