Skip to content

Commit

Permalink
flanneld: adds basic health-check endpoint
Browse files Browse the repository at this point in the history
Begins to address flannel-io#616

Signed-off-by: Gabe Rosenhouse <[email protected]>
  • Loading branch information
Genevieve LEsperance authored and rosenhouse committed Mar 9, 2017
1 parent 840737d commit 019a8f1
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"flag"
"fmt"
"net/http"
"os"
"os/signal"
"strings"
Expand All @@ -33,26 +34,27 @@ import (
"github.com/coreos/flannel/version"

// Backends need to be imported for their init() to get executed and them to register
_ "github.com/coreos/flannel/backend/alivpc"
_ "github.com/coreos/flannel/backend/alloc"
_ "github.com/coreos/flannel/backend/awsvpc"
_ "github.com/coreos/flannel/backend/gce"
_ "github.com/coreos/flannel/backend/hostgw"
_ "github.com/coreos/flannel/backend/udp"
_ "github.com/coreos/flannel/backend/vxlan"
_ "github.com/coreos/flannel/backend/alivpc"
)

type CmdLineOpts struct {
etcdEndpoints string
etcdPrefix string
etcdKeyfile string
etcdCertfile string
etcdCAFile string
etcdUsername string
etcdPassword string
help bool
version bool
kubeSubnetMgr bool
etcdEndpoints string
etcdPrefix string
etcdKeyfile string
etcdCertfile string
etcdCAFile string
etcdUsername string
etcdPassword string
help bool
version bool
kubeSubnetMgr bool
healthCheckPort int
}

var opts CmdLineOpts
Expand All @@ -68,6 +70,7 @@ func init() {
flag.BoolVar(&opts.kubeSubnetMgr, "kube-subnet-mgr", false, "Contact the Kubernetes API for subnet assignement instead of etcd or flannel-server.")
flag.BoolVar(&opts.help, "help", false, "print this message")
flag.BoolVar(&opts.version, "version", false, "print version and exit")
flag.IntVar(&opts.healthCheckPort, "health-check-port", 0, "Run a simple HTTP health-check server on this port")
}

func newSubnetManager() (subnet.Manager, error) {
Expand Down Expand Up @@ -122,15 +125,13 @@ func main() {

ctx, cancel := context.WithCancel(context.Background())

var runFunc func(ctx context.Context)

nm, err := network.NewNetworkManager(ctx, sm)
if err != nil {
log.Error("Failed to create NetworkManager: ", err)
os.Exit(1)
}

runFunc = func(ctx context.Context) {
runFunc := func(ctx context.Context) {
nm.Run(ctx)
}

Expand All @@ -141,6 +142,13 @@ func main() {
wg.Done()
}()

if opts.healthCheckPort > 0 {
go http.ListenAndServe(fmt.Sprintf(":%d", opts.healthCheckPort), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("flanneld is up!\n"))
}))
}

<-sigs
// unregister to get default OS nuke behaviour in case we don't exit cleanly
signal.Stop(sigs)
Expand Down

0 comments on commit 019a8f1

Please sign in to comment.