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