Skip to content

Commit

Permalink
fix: avoid selecting subnets with insufficient available IP addresses
Browse files Browse the repository at this point in the history
Signed-off-by: Vacant2333 <vacant2333@gmail.com>
  • Loading branch information
Vacant2333 committed Jan 23, 2025
1 parent 319b209 commit 66d3323
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/providers/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass)
}

// ZonalSubnetsForLaunch returns a mapping of zone to the subnet with the most available IP addresses and deducts the passed ips from the available count
// nolint:gocyclo
func (p *DefaultProvider) ZonalSubnetsForLaunch(ctx context.Context, nodeClass *v1.EC2NodeClass, instanceTypes []*cloudprovider.InstanceType, capacityType string) (map[string]*Subnet, error) {
if len(nodeClass.Status.Subnets) == 0 {
return nil, fmt.Errorf("no subnets matched selector %v", nodeClass.Spec.SubnetSelectorTerms)
Expand Down Expand Up @@ -168,6 +169,13 @@ func (p *DefaultProvider) ZonalSubnetsForLaunch(ctx context.Context, nodeClass *
if trackedIPs, ok := p.inflightIPs[subnet.ID]; ok {
prevIPs = trackedIPs
}

// Check if the remaining IP count is insufficient to meet the predicted IP usage;
// if so, remove this subnet zone record from inflightIPs and continue to the next item in the loop。
if prevIPs-predictedIPsUsed <= 0 {
delete(zonalSubnets, subnet.Zone)
continue
}
p.inflightIPs[subnet.ID] = prevIPs - predictedIPsUsed
}
return zonalSubnets, nil
Expand Down

0 comments on commit 66d3323

Please sign in to comment.