Skip to content

Commit

Permalink
Merge pull request #334 from chrisdoherty4/bug/incorrect-local-addr
Browse files Browse the repository at this point in the history
Patch incorrect local IPv4 address
  • Loading branch information
mergify[bot] committed Jan 18, 2024
2 parents db71be0 + ccc2ddb commit b3423a0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/backend/kubernetes/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ func toEC2Instance(hw tinkv1.Hardware) ec2.Instance {
for _, ip := range hw.Spec.Metadata.Instance.Ips {
// Public IPv4
if ip.Family == 4 && ip.Public && i.Metadata.PublicIPv4 == "" {
i.Metadata.PublicIPv4 = hw.Spec.Metadata.Instance.Ips[0].Address
i.Metadata.PublicIPv4 = ip.Address
}

// Private IPv4
if ip.Family == 4 && !ip.Public && i.Metadata.LocalIPv4 == "" {
i.Metadata.LocalIPv4 = hw.Spec.Metadata.Instance.Ips[0].Address
i.Metadata.LocalIPv4 = ip.Address
}

// Public IPv6
if ip.Family == 6 && i.Metadata.PublicIPv6 == "" {
i.Metadata.PublicIPv6 = hw.Spec.Metadata.Instance.Ips[0].Address
i.Metadata.PublicIPv6 = ip.Address
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions internal/backend/kubernetes/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,66 @@ func TestGetEC2Instance(t *testing.T) {
},
},
},
{
Name: "PublicThenPrivateIPv4s",
Hardware: tinkv1.Hardware{
Spec: tinkv1.HardwareSpec{
Metadata: &tinkv1.HardwareMetadata{
Instance: &tinkv1.MetadataInstance{
Ips: []*tinkv1.MetadataInstanceIP{
{
Address: "10.10.10.10",
Family: 4,
Public: true,
},
{
Address: "172.15.0.1",
Family: 4,
// Zero value is false but we want to be explicit.
Public: false,
},
},
},
},
},
},
ExpectedInstance: ec2.Instance{
Metadata: ec2.Metadata{
PublicIPv4: "10.10.10.10",
LocalIPv4: "172.15.0.1",
},
},
},
{
Name: "PrivateThenPublicIPv4s",
Hardware: tinkv1.Hardware{
Spec: tinkv1.HardwareSpec{
Metadata: &tinkv1.HardwareMetadata{
Instance: &tinkv1.MetadataInstance{
Ips: []*tinkv1.MetadataInstanceIP{
{
Address: "10.10.10.10",
Family: 4,
// Zero value is false but we want to be explicit.
Public: false,
},
{
Address: "172.15.0.1",
Family: 4,
Public: true,
},
},
},
},
},
},
ExpectedInstance: ec2.Instance{
Metadata: ec2.Metadata{
PublicIPv4: "172.15.0.1",
LocalIPv4: "10.10.10.10",
},
},
},
{
Name: "PublicIPv6",
Hardware: tinkv1.Hardware{
Expand Down

0 comments on commit b3423a0

Please sign in to comment.