Skip to content

Commit

Permalink
Merge pull request #1731 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…1729-to-release-0.16

[release-0.16] topology-updater: properly handle IPv6 from NODE_ADDRESS
  • Loading branch information
k8s-ci-robot committed Jun 4, 2024
2 parents ad7ec5a + a41d0ac commit 00f510b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/nfd-topology-updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package main
import (
"flag"
"fmt"
"net"
"os"
"path"
"strings"
"time"

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

Expand Down Expand Up @@ -128,3 +134,8 @@ func initFlags(flagset *flag.FlagSet) (*topology.Args, *resourcemonitor.Args) {

return args, resourcemonitorArgs
}

func isIPv6(addr string) bool {
ip := net.ParseIP(addr)
return ip != nil && strings.Count(ip.String(), ":") >= 2
}

0 comments on commit 00f510b

Please sign in to comment.