@@ -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
})
@@ -1123,6 +1129,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1123
1129
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).
1124
1130
Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1125
1131
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1132
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1126
1133
secretSvc .EXPECT ().Delete (gomock .Any ()).Return (nil ).MaxTimes (0 )
1127
1134
_ , _ = reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
1128
1135
})
@@ -1205,6 +1212,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1205
1212
secretSvc .EXPECT ().UserData (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , nil ).Times (1 )
1206
1213
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1207
1214
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1215
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1208
1216
1209
1217
_ , err := reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
1210
1218
@@ -1251,6 +1259,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1251
1259
ec2Svc .EXPECT ().CreateInstance (gomock .Any (), gomock .Any (), gomock .Any ()).Return (instance , nil ).AnyTimes ()
1252
1260
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1253
1261
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1262
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1254
1263
1255
1264
ms .AWSMachine .ObjectMeta .Labels = map [string ]string {
1256
1265
clusterv1 .MachineControlPlaneLabelName : "" ,
@@ -1298,6 +1307,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1298
1307
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1299
1308
objectStoreSvc .EXPECT ().Delete (gomock .Any ()).Return (nil ).Times (1 )
1300
1309
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1310
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1301
1311
1302
1312
_ , _ = reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
1303
1313
})
@@ -1379,6 +1389,7 @@ func TestAWSMachineReconciler(t *testing.T) {
1379
1389
instance .State = infrav1 .InstanceStateRunning
1380
1390
ec2Svc .EXPECT ().GetInstanceSecurityGroups (gomock .Any ()).Return (map [string ][]string {"eid" : {}}, nil ).Times (1 )
1381
1391
ec2Svc .EXPECT ().GetCoreSecurityGroups (gomock .Any ()).Return ([]string {}, nil ).Times (1 )
1392
+ ec2Svc .EXPECT ().GetAdditionalSecurityGroupsIDs (gomock .Any ()).Return (nil , nil )
1382
1393
objectStoreSvc .EXPECT ().Delete (gomock .Any ()).Return (nil ).MaxTimes (0 )
1383
1394
_ , _ = reconciler .reconcileNormal (context .Background (), ms , cs , cs , cs , cs )
1384
1395
})
0 commit comments