@@ -1439,6 +1439,18 @@ func TestLaunchTemplateDataCreation(t *testing.T) {
1439
1439
})
1440
1440
}
1441
1441
1442
+ var LaunchTemplateVersionIgnoreUnexported = cmpopts .IgnoreUnexported (
1443
+ ec2types.CapacityReservationTarget {},
1444
+ ec2types.LaunchTemplateCapacityReservationSpecificationRequest {},
1445
+ ec2types.LaunchTemplateIamInstanceProfileSpecificationRequest {},
1446
+ ec2types.LaunchTemplateSpotMarketOptionsRequest {},
1447
+ ec2types.LaunchTemplateInstanceMarketOptionsRequest {},
1448
+ ec2types.Tag {},
1449
+ ec2types.LaunchTemplateTagSpecificationRequest {},
1450
+ ec2types.RequestLaunchTemplateData {},
1451
+ ec2.CreateLaunchTemplateVersionInput {},
1452
+ )
1453
+
1442
1454
func TestCreateLaunchTemplateVersion (t * testing.T ) {
1443
1455
mockCtrl := gomock .NewController (t )
1444
1456
defer mockCtrl .Finish ()
@@ -1459,6 +1471,7 @@ func TestCreateLaunchTemplateVersion(t *testing.T) {
1459
1471
awsResourceReference []infrav1.AWSResourceReference
1460
1472
expect func (m * mocks.MockEC2APIMockRecorder )
1461
1473
wantErr bool
1474
+ mpScopeUpdater func (* scope.MachinePoolScope )
1462
1475
marketType ec2types.MarketType
1463
1476
}{
1464
1477
{
@@ -1506,24 +1519,22 @@ func TestCreateLaunchTemplateVersion(t *testing.T) {
1506
1519
func (ctx context.Context , arg * ec2.CreateLaunchTemplateVersionInput , requestOptions ... request.Option ) {
1507
1520
// formatting added to match tags slice during cmp.Equal()
1508
1521
formatTagsInput (arg )
1509
- if ! cmp .Equal (expectedInput , arg , cmpopts .IgnoreUnexported (
1510
- ec2types.LaunchTemplateIamInstanceProfileSpecificationRequest {},
1511
- ec2types.LaunchTemplateSpotMarketOptionsRequest {},
1512
- ec2types.LaunchTemplateInstanceMarketOptionsRequest {},
1513
- ec2types.Tag {},
1514
- ec2types.LaunchTemplateTagSpecificationRequest {},
1515
- ec2types.RequestLaunchTemplateData {},
1516
- ec2.CreateLaunchTemplateVersionInput {},
1517
- )) {
1518
- t .Fatalf ("mismatch in input expected: %+v, but got %+v, diff: %s" , expectedInput , arg , cmp .Diff (expectedInput , arg ))
1522
+ if ! cmp .Equal (expectedInput , arg , LaunchTemplateVersionIgnoreUnexported ) {
1523
+ t .Fatalf ("mismatch in input expected: %+v, but got %+v, diff: %s" , expectedInput , arg , cmp .Diff (expectedInput , arg , LaunchTemplateVersionIgnoreUnexported ))
1519
1524
}
1520
1525
})
1521
1526
},
1522
1527
},
1523
1528
{
1524
1529
name : "Should successfully create launch template version with capacity-block" ,
1525
1530
awsResourceReference : []infrav1.AWSResourceReference {{ID : aws .String ("1" )}},
1526
- marketType : ec2types .MarketTypeCapacityBlock ,
1531
+ mpScopeUpdater : func (mps * scope.MachinePoolScope ) {
1532
+ spec := mps .AWSMachinePool .Spec
1533
+ spec .AWSLaunchTemplate .CapacityReservationID = aws .String ("cr-12345678901234567" )
1534
+ spec .AWSLaunchTemplate .MarketType = infrav1 .MarketTypeCapacityBlock
1535
+ spec .AWSLaunchTemplate .SpotMarketOptions = nil
1536
+ mps .AWSMachinePool .Spec = spec
1537
+ },
1527
1538
expect : func (m * mocks.MockEC2APIMockRecorder ) {
1528
1539
sgMap := make (map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup )
1529
1540
sgMap [infrav1 .SecurityGroupNode ] = infrav1.SecurityGroup {ID : "1" }
@@ -1542,6 +1553,11 @@ func TestCreateLaunchTemplateVersion(t *testing.T) {
1542
1553
InstanceMarketOptions : & ec2types.LaunchTemplateInstanceMarketOptionsRequest {
1543
1554
MarketType : ec2types .MarketTypeCapacityBlock ,
1544
1555
},
1556
+ CapacityReservationSpecification : & ec2types.LaunchTemplateCapacityReservationSpecificationRequest {
1557
+ CapacityReservationTarget : & ec2types.CapacityReservationTarget {
1558
+ CapacityReservationId : aws .String ("cr-12345678901234567" ),
1559
+ },
1560
+ },
1545
1561
TagSpecifications : []ec2types.LaunchTemplateTagSpecificationRequest {
1546
1562
{
1547
1563
ResourceType : ec2types .ResourceTypeInstance ,
@@ -1563,16 +1579,66 @@ func TestCreateLaunchTemplateVersion(t *testing.T) {
1563
1579
func (ctx context.Context , arg * ec2.CreateLaunchTemplateVersionInput , requestOptions ... request.Option ) {
1564
1580
// formatting added to match tags slice during cmp.Equal()
1565
1581
formatTagsInput (arg )
1566
- if ! cmp .Equal (expectedInput , arg , cmpopts .IgnoreUnexported (
1567
- ec2types.LaunchTemplateIamInstanceProfileSpecificationRequest {},
1568
- ec2types.LaunchTemplateSpotMarketOptionsRequest {},
1569
- ec2types.LaunchTemplateInstanceMarketOptionsRequest {},
1570
- ec2types.Tag {},
1571
- ec2types.LaunchTemplateTagSpecificationRequest {},
1572
- ec2types.RequestLaunchTemplateData {},
1573
- ec2.CreateLaunchTemplateVersionInput {},
1574
- )) {
1575
- t .Fatalf ("mismatch in input expected: %+v, but got %+v, diff: %s" , expectedInput , arg , cmp .Diff (expectedInput , arg ))
1582
+ if ! cmp .Equal (expectedInput , arg , LaunchTemplateVersionIgnoreUnexported ) {
1583
+ t .Fatalf ("mismatch in input expected: %+v, but got %+v, diff: %s" , expectedInput , arg , cmp .Diff (expectedInput , arg , LaunchTemplateVersionIgnoreUnexported ))
1584
+ }
1585
+ })
1586
+ },
1587
+ },
1588
+ {
1589
+ name : "Should successfully create launch template version with capacity reservation ID and preference" ,
1590
+ awsResourceReference : []infrav1.AWSResourceReference {{ID : aws .String ("1" )}},
1591
+ mpScopeUpdater : func (mps * scope.MachinePoolScope ) {
1592
+ spec := mps .AWSMachinePool .Spec
1593
+ spec .AWSLaunchTemplate .CapacityReservationID = aws .String ("cr-12345678901234567" )
1594
+ spec .AWSLaunchTemplate .CapacityReservationPreference = infrav1 .CapacityReservationPreferenceOnly
1595
+ spec .AWSLaunchTemplate .SpotMarketOptions = nil
1596
+ mps .AWSMachinePool .Spec = spec
1597
+ },
1598
+ expect : func (m * mocks.MockEC2APIMockRecorder ) {
1599
+ sgMap := make (map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup )
1600
+ sgMap [infrav1 .SecurityGroupNode ] = infrav1.SecurityGroup {ID : "1" }
1601
+ sgMap [infrav1 .SecurityGroupLB ] = infrav1.SecurityGroup {ID : "2" }
1602
+
1603
+ expectedInput := & ec2.CreateLaunchTemplateVersionInput {
1604
+ LaunchTemplateData : & ec2types.RequestLaunchTemplateData {
1605
+ InstanceType : ec2types .InstanceTypeT3Large ,
1606
+ IamInstanceProfile : & ec2types.LaunchTemplateIamInstanceProfileSpecificationRequest {
1607
+ Name : aws .String ("instance-profile" ),
1608
+ },
1609
+ KeyName : aws .String ("default" ),
1610
+ UserData : ptr.To [string ](base64 .StdEncoding .EncodeToString (userData )),
1611
+ SecurityGroupIds : []string {"nodeSG" , "lbSG" , "1" },
1612
+ ImageId : aws .String ("imageID" ),
1613
+ CapacityReservationSpecification : & ec2types.LaunchTemplateCapacityReservationSpecificationRequest {
1614
+ CapacityReservationTarget : & ec2types.CapacityReservationTarget {
1615
+ CapacityReservationId : aws .String ("cr-12345678901234567" ),
1616
+ },
1617
+ CapacityReservationPreference : ec2types .CapacityReservationPreferenceCapacityReservationsOnly ,
1618
+ },
1619
+ TagSpecifications : []ec2types.LaunchTemplateTagSpecificationRequest {
1620
+ {
1621
+ ResourceType : ec2types .ResourceTypeInstance ,
1622
+ Tags : defaultEC2AndDataTags ("aws-mp-name" , "cluster-name" , userDataSecretKey , testBootstrapDataHash ),
1623
+ },
1624
+ {
1625
+ ResourceType : ec2types .ResourceTypeVolume ,
1626
+ Tags : defaultEC2Tags ("aws-mp-name" , "cluster-name" ),
1627
+ },
1628
+ },
1629
+ },
1630
+ LaunchTemplateId : aws .String ("launch-template-id" ),
1631
+ }
1632
+ m .CreateLaunchTemplateVersion (context .TODO (), gomock .AssignableToTypeOf (expectedInput )).Return (& ec2.CreateLaunchTemplateVersionOutput {
1633
+ LaunchTemplateVersion : & ec2types.LaunchTemplateVersion {
1634
+ LaunchTemplateId : aws .String ("launch-template-id" ),
1635
+ },
1636
+ }, nil ).Do (
1637
+ func (ctx context.Context , arg * ec2.CreateLaunchTemplateVersionInput , requestOptions ... request.Option ) {
1638
+ // formatting added to match tags slice during cmp.Equal()
1639
+ formatTagsInput (arg )
1640
+ if ! cmp .Equal (expectedInput , arg , LaunchTemplateVersionIgnoreUnexported ) {
1641
+ t .Fatalf ("mismatch in input expected: %+v, but got %+v, diff: %s" , expectedInput , arg , cmp .Diff (expectedInput , arg , LaunchTemplateVersionIgnoreUnexported ))
1576
1642
}
1577
1643
})
1578
1644
},
@@ -1619,15 +1685,7 @@ func TestCreateLaunchTemplateVersion(t *testing.T) {
1619
1685
func (ctx context.Context , arg * ec2.CreateLaunchTemplateVersionInput , requestOptions ... request.Option ) {
1620
1686
// formatting added to match tags slice during cmp.Equal()
1621
1687
formatTagsInput (arg )
1622
- if ! cmp .Equal (expectedInput , arg , cmpopts .IgnoreUnexported (
1623
- ec2types.LaunchTemplateIamInstanceProfileSpecificationRequest {},
1624
- ec2types.LaunchTemplateSpotMarketOptionsRequest {},
1625
- ec2types.LaunchTemplateInstanceMarketOptionsRequest {},
1626
- ec2types.Tag {},
1627
- ec2types.LaunchTemplateTagSpecificationRequest {},
1628
- ec2types.RequestLaunchTemplateData {},
1629
- ec2.CreateLaunchTemplateVersionInput {},
1630
- )) {
1688
+ if ! cmp .Equal (expectedInput , arg , LaunchTemplateVersionIgnoreUnexported ) {
1631
1689
t .Fatalf ("mismatch in input expected: %+v, got: %+v" , expectedInput , arg )
1632
1690
}
1633
1691
})
@@ -1645,13 +1703,11 @@ func TestCreateLaunchTemplateVersion(t *testing.T) {
1645
1703
cs , err := setupClusterScope (client )
1646
1704
g .Expect (err ).NotTo (HaveOccurred ())
1647
1705
1648
- var ms * scope.MachinePoolScope
1649
- if tc .marketType == ec2types .MarketTypeCapacityBlock {
1650
- ms , err = setupCapacityBlocksMachinePoolScope (client , cs )
1651
- } else {
1652
- ms , err = setupMachinePoolScope (client , cs )
1653
- }
1706
+ ms , err := setupMachinePoolScope (client , cs )
1654
1707
g .Expect (err ).NotTo (HaveOccurred ())
1708
+ if updateScope := tc .mpScopeUpdater ; updateScope != nil {
1709
+ updateScope (ms )
1710
+ }
1655
1711
1656
1712
ms .AWSMachinePool .Spec .AWSLaunchTemplate .AdditionalSecurityGroups = tc .awsResourceReference
1657
1713
0 commit comments