Skip to content

Commit

Permalink
add healthz
Browse files Browse the repository at this point in the history
  • Loading branch information
andyxning committed May 17, 2017
1 parent 008a583 commit d74069e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"flag"
"fmt"
"net"
"net/http"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -48,6 +49,7 @@ import (
_ "github.com/coreos/flannel/backend/udp"
_ "github.com/coreos/flannel/backend/vxlan"
"github.com/coreos/go-systemd/daemon"
"strconv"
)

type CmdLineOpts struct {
Expand All @@ -67,6 +69,8 @@ type CmdLineOpts struct {
subnetDir string
publicIP string
subnetLeaseRenewMargin int
healthzIP string
healthzPort int
}

var (
Expand All @@ -91,6 +95,8 @@ func init() {
flag.BoolVar(&opts.kubeSubnetMgr, "kube-subnet-mgr", false, "Contact the Kubernetes API for subnet assignement instead of etcd.")
flag.BoolVar(&opts.help, "help", false, "print this message")
flag.BoolVar(&opts.version, "version", false, "print version and exit")
flag.StringVar(&opts.healthzIP, "healthz-ip", "0.0.0.0", "The IP address for healthz server to listen")
flag.IntVar(&opts.healthzPort, "healthz-port", 8284, "The port for healthz server to listen")
}

func newSubnetManager() (subnet.Manager, error) {
Expand Down Expand Up @@ -154,6 +160,8 @@ func main() {
ctx, cancel := context.WithCancel(context.Background())
go shutdown(sigs, cancel)

go mustRunHealthz()

// Fetch the network config (i.e. what backend to use etc..).
config, err := getConfig(ctx, sm)
if err == errCanceled {
Expand Down Expand Up @@ -378,3 +386,16 @@ func WriteSubnetFile(path string, nw ip.IP4Net, ipMasq bool, bn backend.Network)
return os.Rename(tempFile, path)
//TODO - is this safe? What if it's not on the same FS?
}

func mustRunHealthz() {
address := net.JoinHostPort(opts.healthzIP, strconv.Itoa(opts.healthzPort))
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("flanneld is running"))
})

if err := http.ListenAndServe(address, nil); err != nil {
log.Errorf("Start healthz server error. %v", err)
panic(err)
}
}

0 comments on commit d74069e

Please sign in to comment.