Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NodeIP autodect in case of dualstack connection #5920

Merged
merged 2 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
if (serviceIPv6 != clusterIPv6) || (dualCluster != dualService) || (serviceIPv4 != clusterIPv4) {
return fmt.Errorf("cluster-cidr: %v and service-cidr: %v, must share the same IP version (IPv4, IPv6 or dual-stack)", nodeConfig.AgentConfig.ClusterCIDRs, nodeConfig.AgentConfig.ServiceCIDRs)
}
if (clusterIPv6 != nodeIPv6) || (dualCluster != dualNode) || (clusterIPv4 != nodeIPv4) {
if (clusterIPv6 && !nodeIPv6) || (dualCluster && !dualNode) || (clusterIPv4 && !nodeIPv4) {
return fmt.Errorf("cluster-cidr: %v and node-ip: %v, must share the same IP version (IPv4, IPv6 or dual-stack)", nodeConfig.AgentConfig.ClusterCIDRs, nodeConfig.AgentConfig.NodeIPs)
}
enableIPv6 := dualCluster || clusterIPv6
Expand Down
10 changes: 9 additions & 1 deletion pkg/netutil/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ func getIPFromInterface(ifaceName string) (string, error) {
}

globalUnicasts := []string{}
globalUnicastsIPv6 := []string{}
for _, addr := range addrs {
ip, _, err := net.ParseCIDR(addr.String())
if err != nil {
return "", errors.Wrapf(err, "unable to parse CIDR for interface %s", iface.Name)
}
// skipping if not ipv4
if ip.To4() == nil {
if ip.IsGlobalUnicast() {
globalUnicastsIPv6 = append(globalUnicastsIPv6, ip.String())
}
continue
}
if ip.IsGlobalUnicast() {
Expand All @@ -49,8 +53,12 @@ func getIPFromInterface(ifaceName string) (string, error) {
if len(globalUnicasts) > 1 {
return "", fmt.Errorf("multiple global unicast addresses defined for %s, please set ip from one of %v", ifaceName, globalUnicasts)
}
if len(globalUnicasts) == 1 {
if len(globalUnicasts) == 1 && len(globalUnicastsIPv6) == 0 {
return globalUnicasts[0], nil
} else if len(globalUnicastsIPv6) > 0 && len(globalUnicasts) == 1 {
return globalUnicasts[0] + "," + globalUnicastsIPv6[0], nil
} else if len(globalUnicastsIPv6) > 0 {
return globalUnicastsIPv6[0], nil
}

return "", fmt.Errorf("can't find ip for interface %s", ifaceName)
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func GetHostnameAndIPs(name string, nodeIPs cli.StringSlice) (string, []net.IP,
return "", nil, err
}
ips = append(ips, hostIP)
hostIPv6, err := apinet.ResolveBindAddress(net.IPv6loopback)
if err == nil && !hostIPv6.Equal(hostIP) {
ips = append(ips, hostIPv6)
}
} else {
var err error
ips, err = ParseStringSliceToIPs(nodeIPs)
Expand Down