Skip to content

Commit

Permalink
Merge pull request #94 from bakins/healthz
Browse files Browse the repository at this point in the history
Add simple healthz handler
  • Loading branch information
linki authored Jul 30, 2018
2 parents 3273f98 + 3889705 commit 1a0a89a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ If you want to increase or decrease the amount of chaos change the interval betw

Remember that `chaoskube` by default kills any pod in all your namespaces, including system pods and itself.

`chaoskube` provides a simple HTTP endpoint that can be used to check that it is running. This can be used for [Kubernetes liveness and readiness probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/). By default, this listens on port 8080. To disable, pass `--metrics-address=""` to `chaoskube`.

## Filtering targets

However, you can limit the search space of `chaoskube` by providing label, annotation and namespace selectors.
Expand Down
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"fmt"
"math/rand"
"net/http"
"os"
"time"

Expand Down Expand Up @@ -35,6 +37,7 @@ var (
interval time.Duration
dryRun bool
debug bool
metricsAddress string
)

func init() {
Expand All @@ -53,6 +56,7 @@ func init() {
kingpin.Flag("interval", "Interval between Pod terminations").Default("10m").DurationVar(&interval)
kingpin.Flag("dry-run", "If true, don't actually do anything.").Default("true").BoolVar(&dryRun)
kingpin.Flag("debug", "Enable debug logging.").BoolVar(&debug)
kingpin.Flag("metrics-address", "Listening address for metrics handler").Default(":8080").StringVar(&metricsAddress)
}

func main() {
Expand Down Expand Up @@ -153,6 +157,20 @@ func main() {
dryRun,
)

if metricsAddress != "" {
http.HandleFunc("/healthz",
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "OK")
})
go func() {
if err := http.ListenAndServe(metricsAddress, nil); err != nil {
log.WithFields(log.Fields{
"err": err,
}).Fatal("failed to start HTTP server")
}
}()
}

for {
if err := chaoskube.TerminateVictim(); err != nil {
log.WithField("err", err).Error("failed to terminate victim")
Expand Down

0 comments on commit 1a0a89a

Please sign in to comment.