@@ -87,6 +87,12 @@ func TestAWSMachineReconciler(t *testing.T) {
8787 }
8888 klog .SetOutput (GinkgoWriter )
8989
90+ // Ensure InstanceMetadataOptions defaults are set (webhook sets these normally, but not in unit tests)
91+ if awsMachine .Spec .InstanceMetadataOptions == nil {
92+ awsMachine .Spec .InstanceMetadataOptions = & infrav1.InstanceMetadataOptions {}
93+ awsMachine .Spec .InstanceMetadataOptions .SetDefaults ()
94+ }
95+
9096 secret := & corev1.Secret {
9197 ObjectMeta : metav1.ObjectMeta {
9298 Name : "bootstrap-data" ,
@@ -346,6 +352,12 @@ func TestAWSMachineReconciler(t *testing.T) {
346352 instance = & infrav1.Instance {
347353 ID : "myMachine" ,
348354 VolumeIDs : []string {"volume-1" , "volume-2" },
355+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
356+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
357+ HTTPPutResponseHopLimit : 1 ,
358+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
359+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
360+ },
349361 }
350362 instance .State = infrav1 .InstanceStatePending
351363
@@ -752,6 +764,12 @@ func TestAWSMachineReconciler(t *testing.T) {
752764 ID : "myMachine" ,
753765 VolumeIDs : []string {"volume-1" , "volume-2" },
754766 AvailabilityZone : "us-east-1" ,
767+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
768+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
769+ HTTPPutResponseHopLimit : 1 ,
770+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
771+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
772+ },
755773 }
756774 instance .State = infrav1 .InstanceStatePending
757775 }
@@ -1008,6 +1026,12 @@ func TestAWSMachineReconciler(t *testing.T) {
10081026 instance = & infrav1.Instance {
10091027 ID : "myMachine" ,
10101028 State : infrav1 .InstanceStatePending ,
1029+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1030+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1031+ HTTPPutResponseHopLimit : 1 ,
1032+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1033+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1034+ },
10111035 }
10121036
10131037 ec2Svc .EXPECT ().GetRunningInstanceByTags (gomock .Any ()).Return (nil , nil ).AnyTimes ()
@@ -1045,6 +1069,12 @@ func TestAWSMachineReconciler(t *testing.T) {
10451069 instance = & infrav1.Instance {
10461070 ID : "myMachine" ,
10471071 State : infrav1 .InstanceStatePending ,
1072+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1073+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1074+ HTTPPutResponseHopLimit : 1 ,
1075+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1076+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1077+ },
10481078 }
10491079
10501080 ec2Svc .EXPECT ().GetRunningInstanceByTags (gomock .Any ()).Return (nil , nil ).AnyTimes ()
@@ -1069,6 +1099,12 @@ func TestAWSMachineReconciler(t *testing.T) {
10691099
10701100 instance = & infrav1.Instance {
10711101 ID : "myMachine" ,
1102+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1103+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1104+ HTTPPutResponseHopLimit : 1 ,
1105+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1106+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1107+ },
10721108 }
10731109
10741110 ms .Machine .Status .NodeRef = & corev1.ObjectReference {
@@ -1205,6 +1241,12 @@ func TestAWSMachineReconciler(t *testing.T) {
12051241
12061242 instance = & infrav1.Instance {
12071243 ID : "myMachine" ,
1244+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1245+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1246+ HTTPPutResponseHopLimit : 1 ,
1247+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1248+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1249+ },
12081250 }
12091251
12101252 ms .AWSMachine .Spec .CloudInit = infrav1.CloudInit {
@@ -1302,6 +1344,12 @@ func TestAWSMachineReconciler(t *testing.T) {
13021344
13031345 instance = & infrav1.Instance {
13041346 ID : "myMachine" ,
1347+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1348+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1349+ HTTPPutResponseHopLimit : 1 ,
1350+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1351+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1352+ },
13051353 }
13061354 instance .State = infrav1 .InstanceStatePending
13071355 secretSvc .EXPECT ().Create (gomock .Any (), gomock .Any ()).Return (secretPrefix , int32 (1 ), nil ).Times (1 )
@@ -1354,6 +1402,12 @@ func TestAWSMachineReconciler(t *testing.T) {
13541402 instance = & infrav1.Instance {
13551403 ID : "myMachine" ,
13561404 State : infrav1 .InstanceStatePending ,
1405+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1406+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1407+ HTTPPutResponseHopLimit : 1 ,
1408+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1409+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1410+ },
13571411 }
13581412 fakeS3URL := "s3://foo"
13591413
@@ -1387,6 +1441,12 @@ func TestAWSMachineReconciler(t *testing.T) {
13871441 instance = & infrav1.Instance {
13881442 ID : "myMachine" ,
13891443 State : infrav1 .InstanceStatePending ,
1444+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1445+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1446+ HTTPPutResponseHopLimit : 1 ,
1447+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1448+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1449+ },
13901450 }
13911451
13921452 //nolint:gosec
@@ -1414,6 +1474,12 @@ func TestAWSMachineReconciler(t *testing.T) {
14141474
14151475 instance = & infrav1.Instance {
14161476 ID : "myMachine" ,
1477+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1478+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1479+ HTTPPutResponseHopLimit : 1 ,
1480+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1481+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1482+ },
14171483 }
14181484
14191485 ms .Machine .Status .NodeRef = & corev1.ObjectReference {
@@ -1497,6 +1563,12 @@ func TestAWSMachineReconciler(t *testing.T) {
14971563
14981564 instance = & infrav1.Instance {
14991565 ID : "myMachine" ,
1566+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1567+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1568+ HTTPPutResponseHopLimit : 1 ,
1569+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1570+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1571+ },
15001572 }
15011573 ec2Svc .EXPECT ().GetRunningInstanceByTags (gomock .Any ()).Return (instance , nil ).AnyTimes ()
15021574 }
@@ -1606,6 +1678,12 @@ func TestAWSMachineReconciler(t *testing.T) {
16061678 instance = & infrav1.Instance {
16071679 ID : "myMachine" ,
16081680 State : infrav1 .InstanceStatePending ,
1681+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1682+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1683+ HTTPPutResponseHopLimit : 1 ,
1684+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1685+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1686+ },
16091687 }
16101688 fakeS3URL := "s3://foo"
16111689
0 commit comments