fix: deduplicate discovered machine IPs

This commit is contained in:
Pavel Sviderski
2025-03-03 18:42:00 +10:00
parent bb51e01c5c
commit 2e49d94fad
+3
View File
@@ -19,6 +19,7 @@ import (
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
"slices"
"strconv" "strconv"
"uncloud/internal/corrosion" "uncloud/internal/corrosion"
"uncloud/internal/docker" "uncloud/internal/docker"
@@ -541,8 +542,10 @@ 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 {
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)