Skip to content

Commit

Permalink
Merge pull request #758 from makhov/fix-join-token-ip-detection
Browse files Browse the repository at this point in the history
Fix IP address detection for join token generation
  • Loading branch information
makhov authored Oct 2, 2024
2 parents b148e8b + 76c0bbd commit 7f42cc2
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions internal/controller/bootstrap/controlplane_bootstrap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"errors"
"fmt"
"net"
"net/netip"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -603,12 +603,17 @@ func (c *ControlPlaneController) findFirstControllerIP(ctx context.Context, firs
break
}
if addr.Type == clusterv1.MachineInternalIP {
ip := net.ParseIP(addr.Address)
if len(ip) == net.IPv4len {
intIPv4Addr = ip.To4().String()
ip, err := netip.ParseAddr(addr.Address)
if err != nil {
continue
}
if ip.Is4() {
intIPv4Addr = ip.String()
break
}
intAddr = fmt.Sprintf("[%s]", ip.To16().String())
if ip.Is6() {
intAddr = fmt.Sprintf("[%s]", ip.WithZone("").String())
}
}
}

Expand All @@ -632,12 +637,17 @@ func (c *ControlPlaneController) findFirstControllerIP(ctx context.Context, firs
break
}
if addrMap["type"] == string(v1.NodeInternalIP) {
ip := net.ParseIP(addrMap["address"].(string))
if len(ip) == net.IPv4len {
intIPv4Addr = ip.To4().String()
ip, err := netip.ParseAddr(addrMap["address"].(string))
if err != nil {
continue
}
if ip.Is4() {
intIPv4Addr = ip.String()
break
}
intAddr = fmt.Sprintf("[%s]", ip.To16().String())
if ip.Is6() {
intAddr = fmt.Sprintf("[%s]", ip.WithZone("").String())
}
}
}
}
Expand Down

0 comments on commit 7f42cc2

Please sign in to comment.