@@ -88,6 +88,12 @@ func TestAWSMachineReconciler(t *testing.T) {
8888 }
8989 klog .SetOutput (GinkgoWriter )
9090
91+ // Ensure InstanceMetadataOptions defaults are set (webhook sets these normally, but not in unit tests)
92+ if awsMachine .Spec .InstanceMetadataOptions == nil {
93+ awsMachine .Spec .InstanceMetadataOptions = & infrav1.InstanceMetadataOptions {}
94+ awsMachine .Spec .InstanceMetadataOptions .SetDefaults ()
95+ }
96+
9197 secret := & corev1.Secret {
9298 ObjectMeta : metav1.ObjectMeta {
9399 Name : "bootstrap-data" ,
@@ -361,6 +367,12 @@ func TestAWSMachineReconciler(t *testing.T) {
361367 instance = & infrav1.Instance {
362368 ID : "myMachine" ,
363369 VolumeIDs : []string {"volume-1" , "volume-2" },
370+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
371+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
372+ HTTPPutResponseHopLimit : 1 ,
373+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
374+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
375+ },
364376 }
365377 instance .State = infrav1 .InstanceStatePending
366378
@@ -766,6 +778,12 @@ func TestAWSMachineReconciler(t *testing.T) {
766778 ID : "myMachine" ,
767779 VolumeIDs : []string {"volume-1" , "volume-2" },
768780 AvailabilityZone : "us-east-1" ,
781+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
782+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
783+ HTTPPutResponseHopLimit : 1 ,
784+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
785+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
786+ },
769787 }
770788 instance .State = infrav1 .InstanceStatePending
771789 }
@@ -1022,6 +1040,12 @@ func TestAWSMachineReconciler(t *testing.T) {
10221040 instance = & infrav1.Instance {
10231041 ID : "myMachine" ,
10241042 State : infrav1 .InstanceStatePending ,
1043+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1044+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1045+ HTTPPutResponseHopLimit : 1 ,
1046+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1047+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1048+ },
10251049 }
10261050
10271051 ec2Svc .EXPECT ().GetRunningInstanceByTags (gomock .Any ()).Return (nil , nil ).AnyTimes ()
@@ -1059,6 +1083,12 @@ func TestAWSMachineReconciler(t *testing.T) {
10591083 instance = & infrav1.Instance {
10601084 ID : "myMachine" ,
10611085 State : infrav1 .InstanceStatePending ,
1086+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1087+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1088+ HTTPPutResponseHopLimit : 1 ,
1089+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1090+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1091+ },
10621092 }
10631093
10641094 ec2Svc .EXPECT ().GetRunningInstanceByTags (gomock .Any ()).Return (nil , nil ).AnyTimes ()
@@ -1083,6 +1113,12 @@ func TestAWSMachineReconciler(t *testing.T) {
10831113
10841114 instance = & infrav1.Instance {
10851115 ID : "myMachine" ,
1116+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1117+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1118+ HTTPPutResponseHopLimit : 1 ,
1119+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1120+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1121+ },
10861122 }
10871123
10881124 ms .Machine .Status .NodeRef = clusterv1.MachineNodeReference {
@@ -1217,6 +1253,12 @@ func TestAWSMachineReconciler(t *testing.T) {
12171253
12181254 instance = & infrav1.Instance {
12191255 ID : "myMachine" ,
1256+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1257+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1258+ HTTPPutResponseHopLimit : 1 ,
1259+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1260+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1261+ },
12201262 }
12211263
12221264 ms .AWSMachine .Spec .CloudInit = infrav1.CloudInit {
@@ -1314,6 +1356,12 @@ func TestAWSMachineReconciler(t *testing.T) {
13141356
13151357 instance = & infrav1.Instance {
13161358 ID : "myMachine" ,
1359+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1360+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1361+ HTTPPutResponseHopLimit : 1 ,
1362+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1363+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1364+ },
13171365 }
13181366 instance .State = infrav1 .InstanceStatePending
13191367 secretSvc .EXPECT ().Create (gomock .Any (), gomock .Any ()).Return (secretPrefix , int32 (1 ), nil ).Times (1 )
@@ -1366,6 +1414,12 @@ func TestAWSMachineReconciler(t *testing.T) {
13661414 instance = & infrav1.Instance {
13671415 ID : "myMachine" ,
13681416 State : infrav1 .InstanceStatePending ,
1417+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1418+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1419+ HTTPPutResponseHopLimit : 1 ,
1420+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1421+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1422+ },
13691423 }
13701424 fakeS3URL := "s3://foo"
13711425
@@ -1399,6 +1453,12 @@ func TestAWSMachineReconciler(t *testing.T) {
13991453 instance = & infrav1.Instance {
14001454 ID : "myMachine" ,
14011455 State : infrav1 .InstanceStatePending ,
1456+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1457+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1458+ HTTPPutResponseHopLimit : 1 ,
1459+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1460+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1461+ },
14021462 }
14031463
14041464 //nolint:gosec
@@ -1426,6 +1486,12 @@ func TestAWSMachineReconciler(t *testing.T) {
14261486
14271487 instance = & infrav1.Instance {
14281488 ID : "myMachine" ,
1489+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1490+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1491+ HTTPPutResponseHopLimit : 1 ,
1492+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1493+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1494+ },
14291495 }
14301496
14311497 ms .Machine .Status .NodeRef = clusterv1.MachineNodeReference {
@@ -1507,6 +1573,12 @@ func TestAWSMachineReconciler(t *testing.T) {
15071573
15081574 instance = & infrav1.Instance {
15091575 ID : "myMachine" ,
1576+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1577+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1578+ HTTPPutResponseHopLimit : 1 ,
1579+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1580+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1581+ },
15101582 }
15111583 ec2Svc .EXPECT ().GetRunningInstanceByTags (gomock .Any ()).Return (instance , nil ).AnyTimes ()
15121584 }
@@ -1616,6 +1688,12 @@ func TestAWSMachineReconciler(t *testing.T) {
16161688 instance = & infrav1.Instance {
16171689 ID : "myMachine" ,
16181690 State : infrav1 .InstanceStatePending ,
1691+ InstanceMetadataOptions : & infrav1.InstanceMetadataOptions {
1692+ HTTPEndpoint : infrav1 .InstanceMetadataEndpointStateEnabled ,
1693+ HTTPPutResponseHopLimit : 1 ,
1694+ HTTPTokens : infrav1 .HTTPTokensStateOptional ,
1695+ InstanceMetadataTags : infrav1 .InstanceMetadataEndpointStateDisabled ,
1696+ },
16191697 }
16201698 fakeS3URL := "s3://foo"
16211699
0 commit comments