Pull node IP and node name from the environment if no flags are given.
This makes the BGP speaker compatible with the Kubernetes downward API,
without having to shovel the container execution through a shell.
@@ -19,6 +19,7 @@ import (
"flag"
"fmt"
"net"
+ "os"
"reflect"
"sort"
@@ -279,6 +280,13 @@ func main() {
port := flag.Int("port", 80, "HTTP listening port")
flag.Parse()
+ if *myIPstr == "" {
+ *myIPstr = os.Getenv("METALLB_NODE_IP")
+ }
+ if *myNode == "" {
+ *myNode = os.Getenv("METALLB_NODE_NAME")
+ }
+
myIP := net.ParseIP(*myIPstr).To4()
if myIP == nil {
glog.Fatalf("Invalid --node-ip %q, must be an IPv4 address", *myIPstr)
