Skip to content

Commit

Permalink
Ignore public IPs when collecting metadata (#7)
Browse files Browse the repository at this point in the history
Instances may have public IPs assigned after they are provisioned. The `vprox` server will fail to start if public IPs aren't yet assigned to the instance. This seems unnecessary because it doesn't need to know the public IP of the instance at all as far as I understand.

This change makes it easier to start vprox servers in ec2 instances with multiple ENIs but no public IPs, and then assign public IPs later. (AWS doesn't let you automatically assign public IPs if an instance is launched with multiple ENIs so there's a period in which we have no public IPs.)
  • Loading branch information
luiscape authored Oct 8, 2024
1 parent ea2c646 commit 2e46050
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions lib/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
type AwsInterface struct {
MacAddress string
InterfaceId string // eni-[XXXXXXXXXX]
PublicIps []string
PrivateIps []string
}

Expand Down Expand Up @@ -47,25 +46,15 @@ func (am *AwsMetadata) GetAddresses() ([]AwsInterface, error) {
return nil, err
}

result, err := am.get(fmt.Sprintf("%s/%s/ipv4-associations", prefix, mac))
result, err := am.get(fmt.Sprintf("%s/%s/local-ipv4s", prefix, mac))
if err != nil {
return nil, err
}
publicIps := strings.Split(result, "\n")
privateIps := make([]string, 0, len(publicIps))

for _, ip := range publicIps {
privateIp, err := am.get(fmt.Sprintf("%s/%s/ipv4-associations/%s", prefix, mac, ip))
if err != nil {
return nil, err
}
privateIps = append(privateIps, privateIp)
return nil, fmt.Errorf("failed to get private IPs for MAC %s: %v", mac, err)
}
privateIps := strings.Split(result, "\n")

interfaces = append(interfaces, AwsInterface{
MacAddress: mac,
InterfaceId: interfaceId,
PublicIps: publicIps,
PrivateIps: privateIps,
})
}
Expand Down

0 comments on commit 2e46050

Please sign in to comment.