mirror of https://github.com/k3s-io/k3s
Added NodeIP autodect in case of dualstack connection
Signed-off-by: Roberto Bonafiglia <roberto.bonafiglia@suse.com>pull/5962/head
parent
82e5da35a9
commit
d90ba30353
|
@ -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
|
||||
|
|
|
@ -32,6 +32,7 @@ func getIPFromInterface(ifaceName string) (string, error) {
|
|||
}
|
||||
|
||||
globalUnicasts := []string{}
|
||||
globalUnicastsIPv6 := []string{}
|
||||
for _, addr := range addrs {
|
||||
ip, _, err := net.ParseCIDR(addr.String())
|
||||
if err != nil {
|
||||
|
@ -39,6 +40,9 @@ func getIPFromInterface(ifaceName string) (string, error) {
|
|||
}
|
||||
// skipping if not ipv4
|
||||
if ip.To4() == nil {
|
||||
if ip.IsGlobalUnicast() {
|
||||
globalUnicastsIPv6 = append(globalUnicastsIPv6, ip.String())
|
||||
}
|
||||
continue
|
||||
}
|
||||
if ip.IsGlobalUnicast() {
|
||||
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue