5
5
"encoding/base64"
6
6
"errors"
7
7
"fmt"
8
+ "slices"
8
9
"sort"
9
10
"strings"
10
11
"time"
@@ -55,6 +56,13 @@ var checkCommand = &cobra.Command{ // nolint:gochecknoglobals
55
56
}
56
57
InstanceProfile = aws .ToString (instanceProfile .InstanceProfileName )
57
58
59
+ allSubnets := slices .Concat (networkConfig .MainSubnets , networkConfig .PodSubnets )
60
+ slices .Sort (allSubnets )
61
+ distinctSubnets := slices .Compact (allSubnets )
62
+ if len (distinctSubnets ) < len (allSubnets ) {
63
+ log .Info ("ℹ️ Found duplicate subnets. We'll test each subnet only once, starting with main." )
64
+ }
65
+
58
66
log .Infof ("ℹ️ Launching EC2 instances in Main subnets" )
59
67
mainInstanceIds , err := launchInstances (cmd .Context (), ec2Client , networkConfig .MainSubnets , instanceProfile .Arn )
60
68
if err != nil {
@@ -247,6 +255,10 @@ func validateSubnets(cmd *cobra.Command, args []string) error {
247
255
func launchInstances (ctx context.Context , ec2Client * ec2.Client , subnets []string , profileArn * string ) ([]string , error ) {
248
256
var instanceIds []string
249
257
for _ , subnet := range subnets {
258
+ if _ , ok := Subnets [subnet ]; ok {
259
+ log .Warnf ("Subnet '%v' was already launched, skipping" , subnet )
260
+ continue
261
+ }
250
262
secGroup , err := createSecurityGroups (ctx , ec2Client , subnet )
251
263
if err != nil {
252
264
return nil , fmt .Errorf ("❌ failed to create security group for subnet '%v': %v" , subnet , err )
@@ -258,6 +270,7 @@ func launchInstances(ctx context.Context, ec2Client *ec2.Client, subnets []strin
258
270
}
259
271
260
272
instanceIds = append (instanceIds , instanceId )
273
+ Subnets [subnet ] = true
261
274
}
262
275
263
276
return instanceIds , nil
0 commit comments