Skip to content

Commit

Permalink
Fix subnet sorting with multiple vpcs when launching an instance
Browse files Browse the repository at this point in the history
Signed-off-by: Cameron McAvoy <[email protected]>
  • Loading branch information
cnmcavoy committed Sep 4, 2024
1 parent 181bdc9 commit b6eda5c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/cloud/services/ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ func (s *Service) findSubnet(scope *scope.MachineScope) (string, error) {

filtered = append(filtered, subnet)
}
// prefer a subnet in the cluster VPC if multiple match
// keep AWS returned orderz stable, but prefer a subnet in the cluster VPC
clusterVPC := s.scope.VPC().ID
sort.SliceStable(filtered, func(i, j int) bool {
return strings.Compare(*filtered[i].VpcId, clusterVPC) > strings.Compare(*filtered[j].VpcId, clusterVPC)
return *filtered[i].VpcId == clusterVPC
})
if len(filtered) == 0 {
errMessage = fmt.Sprintf("failed to run machine %q, found %d subnets matching criteria but post-filtering failed.",
Expand Down

0 comments on commit b6eda5c

Please sign in to comment.