@@ -304,6 +304,128 @@ var _ = Describe("AZ", func() {
304
304
})
305
305
})
306
306
307
+ type unsupportedZoneEntry struct {
308
+ region string
309
+ zoneNameToIDs map [string ]string
310
+ expectedZones []string
311
+ }
312
+ DescribeTable ("region with unsupported zone IDs" , func (e unsupportedZoneEntry ) {
313
+ var azs []ec2types.AvailabilityZone
314
+ for zoneName , zoneID := range e .zoneNameToIDs {
315
+ azs = append (azs , createAvailabilityZoneWithID (e .region , ec2types .AvailabilityZoneStateAvailable , zoneName , zoneID ))
316
+ }
317
+ mockProvider := mockprovider .NewMockProvider ()
318
+ mockProvider .MockEC2 ().On ("DescribeAvailabilityZones" , mock .Anything , & ec2.DescribeAvailabilityZonesInput {
319
+ Filters : []ec2types.Filter {
320
+ {
321
+ Name : aws .String ("region-name" ),
322
+ Values : []string {e .region },
323
+ },
324
+ {
325
+ Name : aws .String ("state" ),
326
+ Values : []string {string (ec2types .AvailabilityZoneStateAvailable )},
327
+ },
328
+ {
329
+ Name : aws .String ("zone-type" ),
330
+ Values : []string {string (ec2types .LocationTypeAvailabilityZone )},
331
+ },
332
+ },
333
+ }).Return (& ec2.DescribeAvailabilityZonesOutput {
334
+ AvailabilityZones : azs ,
335
+ }, nil )
336
+ mockProvider .MockEC2 ().On ("DescribeInstanceTypeOfferings" , mock .Anything , & ec2.DescribeInstanceTypeOfferingsInput {
337
+ Filters : []ec2types.Filter {
338
+ {
339
+ Name : aws .String ("instance-type" ),
340
+ Values : []string {"t2.small" , "t2.medium" },
341
+ },
342
+ {
343
+ Name : aws .String ("location" ),
344
+ Values : []string {"zone1" , "zone2" , "zone3" , "zone4" },
345
+ },
346
+ },
347
+ LocationType : ec2types .LocationTypeAvailabilityZone ,
348
+ MaxResults : aws .Int32 (100 ),
349
+ }, mock .Anything ).Return (& ec2.DescribeInstanceTypeOfferingsOutput {
350
+ NextToken : aws .String ("token" ),
351
+ InstanceTypeOfferings : []ec2types.InstanceTypeOffering {
352
+ {
353
+ InstanceType : "t2.small" ,
354
+ Location : aws .String ("zone1" ),
355
+ LocationType : "availability-zone" ,
356
+ },
357
+ {
358
+ InstanceType : "t2.small" ,
359
+ Location : aws .String ("zone2" ),
360
+ LocationType : "availability-zone" ,
361
+ },
362
+ {
363
+ InstanceType : "t2.small" ,
364
+ Location : aws .String ("zone4" ),
365
+ LocationType : "availability-zone" ,
366
+ },
367
+ {
368
+ InstanceType : "t2.small" ,
369
+ Location : aws .String ("zone3" ),
370
+ LocationType : "availability-zone" ,
371
+ },
372
+ },
373
+ }, nil )
374
+ clusterConfig := api .NewClusterConfig ()
375
+ clusterConfig .Metadata .Region = e .region
376
+ clusterConfig .NodeGroups = []* api.NodeGroup {
377
+ {
378
+ NodeGroupBase : & api.NodeGroupBase {
379
+ Name : "test-az-1" ,
380
+ },
381
+ },
382
+ {
383
+ NodeGroupBase : & api.NodeGroupBase {
384
+ Name : "test-az-2" ,
385
+ },
386
+ },
387
+ }
388
+ zones , err := az .GetAvailabilityZones (context .Background (), mockProvider .MockEC2 (), e .region , clusterConfig )
389
+ Expect (err ).NotTo (HaveOccurred ())
390
+ Expect (zones ).To (ConsistOf (e .expectedZones ))
391
+ },
392
+ Entry (api .RegionCNNorth1 , unsupportedZoneEntry {
393
+ region : api .RegionCNNorth1 ,
394
+ zoneNameToIDs : map [string ]string {
395
+ "zone1" : "cnn1-az1" ,
396
+ "zone2" : "cnn1-az2" ,
397
+ "zone4" : "cnn1-az4" ,
398
+ },
399
+ expectedZones : []string {"zone1" , "zone2" },
400
+ }),
401
+ Entry (api .RegionUSEast1 , unsupportedZoneEntry {
402
+ region : api .RegionUSEast1 ,
403
+ zoneNameToIDs : map [string ]string {
404
+ "zone1" : "use1-az1" ,
405
+ "zone2" : "use1-az3" ,
406
+ "zone3" : "use1-az2" ,
407
+ },
408
+ expectedZones : []string {"zone1" , "zone3" },
409
+ }),
410
+ Entry (api .RegionUSWest1 , unsupportedZoneEntry {
411
+ region : api .RegionUSWest1 ,
412
+ zoneNameToIDs : map [string ]string {
413
+ "zone1" : "usw1-az2" ,
414
+ "zone2" : "usw1-az1" ,
415
+ "zone3" : "usw1-az3" ,
416
+ },
417
+ expectedZones : []string {"zone2" , "zone3" },
418
+ }),
419
+ Entry (api .RegionCACentral1 , unsupportedZoneEntry {
420
+ region : api .RegionCACentral1 ,
421
+ zoneNameToIDs : map [string ]string {
422
+ "zone1" : "cac1-az1" ,
423
+ "zone2" : "cac1-az2" ,
424
+ "zone3" : "cac1-az3" ,
425
+ },
426
+ expectedZones : []string {"zone1" , "zone2" },
427
+ }),
428
+ )
307
429
When ("the region contains zones that are denylisted" , func () {
308
430
BeforeEach (func () {
309
431
region = api .RegionCNNorth1
0 commit comments