|
@@ -19,11 +19,13 @@ import (
|
|
"flag"
|
|
"flag"
|
|
"fmt"
|
|
"fmt"
|
|
"net"
|
|
"net"
|
|
|
|
+ "net/http"
|
|
"os"
|
|
"os"
|
|
"os/signal"
|
|
"os/signal"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
"strings"
|
|
"strings"
|
|
"syscall"
|
|
"syscall"
|
|
|
|
+ "strconv"
|
|
|
|
|
|
"github.com/coreos/pkg/flagutil"
|
|
"github.com/coreos/pkg/flagutil"
|
|
log "github.com/golang/glog"
|
|
log "github.com/golang/glog"
|
|
@@ -67,6 +69,8 @@ type CmdLineOpts struct {
|
|
subnetDir string
|
|
subnetDir string
|
|
publicIP string
|
|
publicIP string
|
|
subnetLeaseRenewMargin int
|
|
subnetLeaseRenewMargin int
|
|
|
|
+ healthzIP string
|
|
|
|
+ healthzPort int
|
|
}
|
|
}
|
|
|
|
|
|
var (
|
|
var (
|
|
@@ -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.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.help, "help", false, "print this message")
|
|
flag.BoolVar(&opts.version, "version", false, "print version and exit")
|
|
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", 0, "The port for healthz server to listen(0 to disable)")
|
|
}
|
|
}
|
|
|
|
|
|
func newSubnetManager() (subnet.Manager, error) {
|
|
func newSubnetManager() (subnet.Manager, error) {
|
|
@@ -154,6 +160,10 @@ func main() {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
go shutdown(sigs, cancel)
|
|
go shutdown(sigs, cancel)
|
|
|
|
|
|
|
|
+ if opts.healthzPort > 0 {
|
|
|
|
+ go mustRunHealthz()
|
|
|
|
+ }
|
|
|
|
+
|
|
// Fetch the network config (i.e. what backend to use etc..).
|
|
// Fetch the network config (i.e. what backend to use etc..).
|
|
config, err := getConfig(ctx, sm)
|
|
config, err := getConfig(ctx, sm)
|
|
if err == errCanceled {
|
|
if err == errCanceled {
|
|
@@ -378,3 +388,18 @@ func WriteSubnetFile(path string, nw ip.IP4Net, ipMasq bool, bn backend.Network)
|
|
return os.Rename(tempFile, path)
|
|
return os.Rename(tempFile, path)
|
|
//TODO - is this safe? What if it's not on the same FS?
|
|
//TODO - is this safe? What if it's not on the same FS?
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func mustRunHealthz() {
|
|
|
|
+ address := net.JoinHostPort(opts.healthzIP, strconv.Itoa(opts.healthzPort))
|
|
|
|
+ log.Infof("Start healthz server on %s", address)
|
|
|
|
+
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
|
|
+}
|