Skip to content

Commit

Permalink
node: always get the public IPv4 from an external service to handle N…
Browse files Browse the repository at this point in the history
…ATed cloud nodes
  • Loading branch information
maxmouchet committed Sep 28, 2021
1 parent 76ff0a5 commit d7fa38b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,21 @@ func getHostnameRoot(platform string) string {
func getIPv4(platform string) (net.IP, net.IP) {
switch platform {
case platforms.Azure:
// The NIC public IP is not available through Azure metadata...
// https://docs.microsoft.com/en-us/answers/questions/7932/public-ip-not-available-via-metadata.html
localIP := net.ParseIP(platforms.AzureGetMetadata("network/interface/0/ipv4/ipAddress/0/privateIpAddress"))
publicIP := network.PublicIPv4()
return localIP, publicIP
case platforms.EC2:
localIP := net.ParseIP(platforms.EC2GetMetadata("local-ipv4"))
publicIP := net.ParseIP(platforms.EC2GetMetadata("public-ipv4"))
publicIP := network.PublicIPv4()
return localIP, publicIP
case platforms.GCP:
localIP := net.ParseIP(platforms.GCPGetMetadata("instance/network-interfaces/0/ip"))
publicIP := net.ParseIP(platforms.GCPGetMetadata("instance/network-interfaces/0/access-configs/0/external-ip"))
publicIP := network.PublicIPv4()
return localIP, publicIP
case platforms.SCW:
meta := platforms.SCWGetMetadata()
localIP := net.ParseIP(meta.PrivateIP)
publicIP := net.ParseIP(meta.PublicIP.Address)
publicIP := network.PublicIPv4()
return localIP, publicIP
default:
localIP := network.LocalIPv4()
Expand Down

0 comments on commit d7fa38b

Please sign in to comment.