Skip to content

Commit

Permalink
check subnets, too for now and ensure target is in both the vpc descr…
Browse files Browse the repository at this point in the history
…iption and each subnet found, otherwise, add the "all" AZ tag
  • Loading branch information
nullren committed May 28, 2024
1 parent d431bc6 commit e444d99
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/targetgroupbinding/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,19 @@ func (m *defaultResourceManager) registerPodEndpoints(ctx context.Context, tgARN
return err
}

var subnetRawCIDRs []string
subnetInfo, err := m.subnetProvider.ResolveViaSelector(ctx, &elbv2api.SubnetSelector{})
if err != nil {
return err
}
for _, si := range subnetInfo {
subnetRawCIDRs = append(subnetRawCIDRs, *si.CidrBlock)
}
subnetCIDRs, err := networking.ParseCIDRs(subnetRawCIDRs)
if err != nil {
return err
}

sdkTargets := make([]elbv2sdk.TargetDescription, 0, len(endpoints))
for _, endpoint := range endpoints {
target := elbv2sdk.TargetDescription{
Expand All @@ -416,7 +429,7 @@ func (m *defaultResourceManager) registerPodEndpoints(ctx context.Context, tgARN
if err != nil {
return err
}
if !networking.IsIPWithinCIDRs(podIP, vpcCIDRs) {
if !networking.IsIPWithinCIDRs(podIP, vpcCIDRs) || !networking.IsIPWithinCIDRs(podIP, subnetCIDRs) {
target.AvailabilityZone = awssdk.String("all")
}
sdkTargets = append(sdkTargets, target)
Expand Down

0 comments on commit e444d99

Please sign in to comment.