@@ -450,6 +450,7 @@ func TestAWSMachineReconciler(t *testing.T) {
450
450
},
451
451
}
452
452
ec2Svc .EXPECT ().UpdateInstanceSecurityGroups (instance .ID , []string {"sg-2345" })
453
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return ([]string {"sg-2345" }, nil )
453
454
454
455
_ , _ = reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
455
456
expectConditions (g , ms .AWSMachine , []conditionAssertion {{conditionType : infrav1 .SecurityGroupsReadyCondition , status : corev1 .ConditionTrue }})
@@ -463,6 +464,7 @@ func TestAWSMachineReconciler(t *testing.T) {
463
464
instanceCreate (t , g )
464
465
getCoreSecurityGroups (t , g )
465
466
467
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
466
468
ec2Svc .EXPECT ().UpdateInstanceSecurityGroups (gomock .Any (), gomock .Any ()).Times (0 )
467
469
if _ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs ); err != nil {
468
470
_ = fmt .Errorf ("reconcileNormal reutrned an error during test" )
@@ -480,6 +482,7 @@ func TestAWSMachineReconciler(t *testing.T) {
480
482
ms .AWSMachine .Spec .AdditionalTags = infrav1.Tags {"kind" : "alicorn" }
481
483
cs .AWSCluster .Spec .AdditionalTags = infrav1.Tags {"colour" : "lavender" }
482
484
485
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
483
486
ec2Svc .EXPECT ().UpdateResourceTags (
484
487
gomock .Any (),
485
488
map [string ]string {
@@ -510,6 +513,7 @@ func TestAWSMachineReconciler(t *testing.T) {
510
513
511
514
ms .AWSMachine .Spec .AdditionalTags = infrav1.Tags {"rootDeviceID" : "id1" , "rootDeviceSize" : "30" }
512
515
516
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
513
517
ec2Svc .EXPECT ().UpdateResourceTags (
514
518
gomock .Any (),
515
519
map [string ]string {
@@ -536,6 +540,7 @@ func TestAWSMachineReconciler(t *testing.T) {
536
540
secretSvc .EXPECT ().UserData (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , nil ).Times (1 )
537
541
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
538
542
secretSvc .EXPECT ().Create (gomock .Any (), gomock .Any ()).Return ("test" , int32 (1 ), nil ).Times (1 )
543
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
539
544
}
540
545
541
546
t .Run ("should set instance to stopping and unready" , func (t * testing.T ) {
@@ -646,6 +651,7 @@ func TestAWSMachineReconciler(t *testing.T) {
646
651
secretSvc .EXPECT ().Create (gomock .Any (), gomock .Any ()).Return ("test" , int32 (1 ), nil ).Times (1 )
647
652
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
648
653
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
654
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
649
655
650
656
_ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
651
657
g .Expect (err ).To (BeNil ())
@@ -671,6 +677,7 @@ func TestAWSMachineReconciler(t *testing.T) {
671
677
secretSvc .EXPECT ().Create (gomock .Any (), gomock .Any ()).Return ("test" , int32 (1 ), nil ).Times (1 )
672
678
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
673
679
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
680
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
674
681
675
682
_ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
676
683
g .Expect (err ).To (BeNil ())
@@ -688,6 +695,7 @@ func TestAWSMachineReconciler(t *testing.T) {
688
695
ms .AWSMachine .Spec .CloudInit .InsecureSkipSecretsManager = true
689
696
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
690
697
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
698
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
691
699
reconciler .elbServiceFactory = func (elbScope scope.ELBScope ) services.ELBInterface {
692
700
return elbSvc
693
701
}
@@ -918,8 +926,6 @@ func TestAWSMachineReconciler(t *testing.T) {
918
926
ms .AWSMachine .Annotations = map [string ]string {SecurityGroupsLastAppliedAnnotation : "{\" tag\" :\" tag1\" }" }
919
927
ms .AWSMachine .Spec .AdditionalSecurityGroups = []infrav1.AWSResourceReference {
920
928
{
921
- ID : aws .String ("sg-1" ),
922
- ARN : aws .String ("arn-1" ),
923
929
Filters : []infrav1.Filter {
924
930
{
925
931
Name : "example-name" ,
@@ -930,7 +936,7 @@ func TestAWSMachineReconciler(t *testing.T) {
930
936
}
931
937
932
938
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil )
933
- ec2Svc .EXPECT ().GetFilteredSecurityGroupID (gomock .Any ()).Return ("sg-1" , errors .New ("failed to get filtered SGs" ))
939
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return ([] string { "sg-1" } , errors .New ("failed to get filtered SGs" ))
934
940
935
941
_ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
936
942
g .Expect (err ).To (BeNil ())
@@ -950,20 +956,18 @@ func TestAWSMachineReconciler(t *testing.T) {
950
956
ms .AWSMachine .Annotations = map [string ]string {SecurityGroupsLastAppliedAnnotation : "{\" tag\" :\" tag1\" }" }
951
957
ms .AWSMachine .Spec .AdditionalSecurityGroups = []infrav1.AWSResourceReference {
952
958
{
953
- ID : aws .String ("sg-1" ),
954
- ARN : aws .String ("arn-1" ),
955
959
Filters : []infrav1.Filter {
956
960
{
957
- Name : "example-name " ,
958
- Values : []string {"example-value " },
961
+ Name : "id " ,
962
+ Values : []string {"sg-1 " },
959
963
},
960
964
},
961
965
},
962
966
}
963
967
964
- ec2Svc .EXPECT ().GetFilteredSecurityGroupID (gomock .Any ()).Return ("sg-1" , nil )
965
968
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil )
966
969
ec2Svc .EXPECT ().UpdateInstanceSecurityGroups (gomock .Any (), gomock .Any ()).Return (errors .New ("failed to update security groups" ))
970
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return ([]string {"sg-1" }, nil )
967
971
968
972
_ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
969
973
g .Expect (err ).ToNot (BeNil ())
@@ -996,6 +1000,7 @@ func TestAWSMachineReconciler(t *testing.T) {
996
1000
secretSvc .EXPECT ().UserData (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , nil ).Times (1 )
997
1001
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
998
1002
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1003
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
999
1004
1000
1005
ms .AWSMachine .ObjectMeta .Labels = map [string ]string {
1001
1006
clusterv1 .MachineControlPlaneLabelName : "" ,
@@ -1038,6 +1043,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1038
1043
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).
1039
1044
Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1040
1045
secretSvc .EXPECT ().Delete (gomock .Any ()).Return (nil ).Times (1 )
1046
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1041
1047
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1042
1048
_ , _ = reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
1043
1049
})
@@ -1109,6 +1115,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1109
1115
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).
1110
1116
Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1111
1117
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1118
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1112
1119
secretSvc .EXPECT ().Delete (gomock .Any ()).Return (nil ).MaxTimes (0 )
1113
1120
_ , _ = reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
1114
1121
})
@@ -1191,6 +1198,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1191
1198
secretSvc .EXPECT ().UserData (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , nil ).Times (1 )
1192
1199
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1193
1200
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1201
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1194
1202
1195
1203
_ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
1196
1204
@@ -1237,6 +1245,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1237
1245
ec2Svc .EXPECT ().CreateInstance (gomock .Any (), gomock .Any (), gomock .Any ()).Return (instance , nil ).AnyTimes ()
1238
1246
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1239
1247
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1248
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1240
1249
1241
1250
ms .AWSMachine .ObjectMeta .Labels = map [string ]string {
1242
1251
clusterv1 .MachineControlPlaneLabelName : "" ,
@@ -1284,6 +1293,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1284
1293
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1285
1294
objectStoreSvc .EXPECT ().Delete (gomock .Any ()).Return (nil ).Times (1 )
1286
1295
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1296
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1287
1297
1288
1298
_ , _ = reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
1289
1299
})
@@ -1365,6 +1375,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1365
1375
instance .State = infrav1 .InstanceStateRunning
1366
1376
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1367
1377
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1378
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1368
1379
objectStoreSvc .EXPECT ().Delete (gomock .Any ()).Return (nil ).MaxTimes (0 )
1369
1380
_ , _ = reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
1370
1381
})
0 commit comments