Skip to content

Commit d81c9a2

Browse files
committed
Register as instances on both IPv4 & 6
Signed-off-by: Nolan Brubaker <nolan@nbrubaker.com>
1 parent 4d5b485 commit d81c9a2

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

pkg/providers/v1/aws_loadbalancer.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -993,23 +993,19 @@ func (c *Cloud) computeTargetGroupExpectedTargets(instances map[InstanceID]*ec2t
993993

994994
for instanceID, instance := range instances {
995995
if ipAddressType == elbv2types.TargetGroupIpAddressTypeEnumIpv6 {
996-
// For IPv6 target groups, register using the instance's IPv6 address
996+
// For IPv6 target groups, verify instance has IPv6 address before registering
997997
ipv6Address := extractInstanceIPv6Address(instance)
998-
if ipv6Address != "" {
999-
expectedTargets = append(expectedTargets, &elbv2types.TargetDescription{
1000-
Id: aws.String(ipv6Address),
1001-
Port: aws.Int32(port),
1002-
})
1003-
} else {
998+
if ipv6Address == "" {
1004999
klog.Warningf("Instance %s has no IPv6 address, skipping registration to IPv6 target group", instanceID)
1000+
continue
10051001
}
1006-
} else {
1007-
// For IPv4 target groups, register using the instance ID
1008-
expectedTargets = append(expectedTargets, &elbv2types.TargetDescription{
1009-
Id: aws.String(string(instanceID)),
1010-
Port: aws.Int32(port),
1011-
})
10121002
}
1003+
// Register using instance ID for both IPv4 and IPv6 target groups
1004+
// AWS will route to the appropriate IP address based on the target group's IpAddressType
1005+
expectedTargets = append(expectedTargets, &elbv2types.TargetDescription{
1006+
Id: aws.String(string(instanceID)),
1007+
Port: aws.Int32(port),
1008+
})
10131009
}
10141010
return expectedTargets
10151011
}

pkg/providers/v1/aws_loadbalancer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ func TestCloud_computeTargetGroupExpectedTargets(t *testing.T) {
11001100
},
11011101
want: []*elbv2types.TargetDescription{
11021102
{
1103-
Id: aws.String("2001:db8::1"),
1103+
Id: aws.String("i-abcdef1"),
11041104
Port: aws.Int32(8080),
11051105
},
11061106
},
@@ -1151,15 +1151,15 @@ func TestCloud_computeTargetGroupExpectedTargets(t *testing.T) {
11511151
},
11521152
want: []*elbv2types.TargetDescription{
11531153
{
1154-
Id: aws.String("2001:db8::1"),
1154+
Id: aws.String("i-abcdef1"),
11551155
Port: aws.Int32(8080),
11561156
},
11571157
{
1158-
Id: aws.String("2001:db8::2"),
1158+
Id: aws.String("i-abcdef2"),
11591159
Port: aws.Int32(8080),
11601160
},
11611161
{
1162-
Id: aws.String("2001:db8::3"),
1162+
Id: aws.String("i-abcdef3"),
11631163
Port: aws.Int32(8080),
11641164
},
11651165
},

0 commit comments

Comments
 (0)