fix: deduplicate discovered machine IPs when adding a new machine

This commit is contained in:
Pavel Sviderski
2025-03-05 09:14:11 +10:00
parent 805afd0d28
commit 2a82f75cad
+2 -4
View File
@@ -541,11 +541,9 @@ func (m *Machine) InitCluster(ctx context.Context, req *pb.InitClusterRequest) (
} }
publicIP, pubIPErr := network.GetPublicIP() publicIP, pubIPErr := network.GetPublicIP()
// Ignore the error if failed to get the public IP using API services. // Ignore the error if failed to get the public IP using API services.
if pubIPErr == nil { if pubIPErr == nil && !slices.Contains(ips, publicIP) {
if !slices.Contains(ips, publicIP) {
ips = append(ips, publicIP) ips = append(ips, publicIP)
} }
}
endpoints := make([]*pb.IPPort, len(ips)) endpoints := make([]*pb.IPPort, len(ips))
for i, addr := range ips { for i, addr := range ips {
addrPort := netip.AddrPortFrom(addr, network.WireGuardPort) addrPort := netip.AddrPortFrom(addr, network.WireGuardPort)
@@ -685,7 +683,7 @@ func (m *Machine) Token(_ context.Context, _ *emptypb.Empty) (*pb.TokenResponse,
} }
publicIP, err := network.GetPublicIP() publicIP, err := network.GetPublicIP()
// Ignore the error if failed to get the public IP using API services. // Ignore the error if failed to get the public IP using API services.
if err == nil { if err == nil && !slices.Contains(ips, publicIP) {
ips = append(ips, publicIP) ips = append(ips, publicIP)
} }
endpoints := make([]netip.AddrPort, len(ips)) endpoints := make([]netip.AddrPort, len(ips))