Skip to content

Commit d229441

Browse files
marquizk8s-infra-cherrypick-robot
authored andcommitted
topology-updater: properly handle IPv6 from NODE_ADDRESS
Fix the usage of IPv6 addresses for default kubelet configz endpoint. The default host:port we use for kubelet configz endpoint is ${NODE_ADDRESS}:10250. Previously we errored out if NODE_ADDRESS was an IPv6 address because we used an incorrect notation (without brackets). The (IPv6) needs to be enclosed in brackets if specifying the port.
1 parent 089509a commit d229441

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmd/nfd-topology-updater/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ package main
1919
import (
2020
"flag"
2121
"fmt"
22+
"net"
2223
"os"
2324
"path"
25+
"strings"
2426
"time"
2527

2628
"k8s.io/klog/v2"
@@ -89,6 +91,10 @@ func parseArgs(flags *flag.FlagSet, osArgs ...string) (*topology.Args, *resource
8991
"please either define the NODE_ADDRESS environment variable or specify endpoint with the -kubelet-config-uri flag\n", kubeletSecurePort)
9092
os.Exit(1)
9193
}
94+
if isIPv6(nodeAddress) {
95+
// With IPv6 we need to wrap the IP address in brackets as we append :port below
96+
nodeAddress = "[" + nodeAddress + "]"
97+
}
9298
resourcemonitorArgs.KubeletConfigURI = fmt.Sprintf("https://%s:%d/configz", nodeAddress, kubeletSecurePort)
9399
}
94100

@@ -126,3 +132,8 @@ func initFlags(flagset *flag.FlagSet) (*topology.Args, *resourcemonitor.Args) {
126132

127133
return args, resourcemonitorArgs
128134
}
135+
136+
func isIPv6(addr string) bool {
137+
ip := net.ParseIP(addr)
138+
return ip != nil && strings.Count(ip.String(), ":") >= 2
139+
}

0 commit comments

Comments
 (0)