@@ -40,6 +40,8 @@ import (
40
40
"sigs.k8s.io/controller-runtime/pkg/client/fake"
41
41
)
42
42
43
+ var fdList = []string {"FAULT-DOMAIN-1" , "FAULT-DOMAIN-2" , "FAULT-DOMAIN-3" }
44
+
43
45
func TestInstanceReconciliation (t * testing.T ) {
44
46
var (
45
47
ms * MachineScope
@@ -277,6 +279,47 @@ func TestInstanceReconciliation(t *testing.T) {
277
279
})).Return (core.LaunchInstanceResponse {}, nil )
278
280
},
279
281
},
282
+ {
283
+ name : "try all fds" ,
284
+ errorExpected : true ,
285
+ matchError : TestError {errorString : ociutil .OutOfHostCapacityErr },
286
+ testSpecificSetup : func (machineScope * MachineScope , computeClient * mock_compute.MockComputeClient ) {
287
+ setupAllParams (ms )
288
+ computeClient .EXPECT ().ListInstances (gomock .Any (), gomock .Eq (core.ListInstancesRequest {
289
+ DisplayName : common .String ("name" ),
290
+ CompartmentId : common .String ("test" ),
291
+ })).Return (core.ListInstancesResponse {}, nil )
292
+
293
+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
294
+ return instanceFDMatcher (request , "FAULT-DOMAIN-1" )
295
+ })).Return (core.LaunchInstanceResponse {}, TestError {errorString : ociutil .OutOfHostCapacityErr })
296
+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
297
+ return instanceFDMatcher (request , "FAULT-DOMAIN-2" )
298
+ })).Return (core.LaunchInstanceResponse {}, TestError {errorString : ociutil .OutOfHostCapacityErr })
299
+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
300
+ return instanceFDMatcher (request , "FAULT-DOMAIN-3" )
301
+ })).Return (core.LaunchInstanceResponse {}, TestError {errorString : ociutil .OutOfHostCapacityErr })
302
+ },
303
+ },
304
+ {
305
+ name : "second fd works" ,
306
+ errorExpected : false ,
307
+ matchError : TestError {errorString : ociutil .OutOfHostCapacityErr },
308
+ testSpecificSetup : func (machineScope * MachineScope , computeClient * mock_compute.MockComputeClient ) {
309
+ setupAllParams (ms )
310
+ computeClient .EXPECT ().ListInstances (gomock .Any (), gomock .Eq (core.ListInstancesRequest {
311
+ DisplayName : common .String ("name" ),
312
+ CompartmentId : common .String ("test" ),
313
+ })).Return (core.ListInstancesResponse {}, nil )
314
+
315
+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
316
+ return anyFdMatcher (request )
317
+ })).Return (core.LaunchInstanceResponse {}, TestError {errorString : ociutil .OutOfHostCapacityErr })
318
+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
319
+ return anyFdMatcher (request )
320
+ })).Return (core.LaunchInstanceResponse {}, nil )
321
+ },
322
+ },
280
323
{
281
324
name : "check compartment at cluster" ,
282
325
errorExpected : false ,
@@ -341,6 +384,7 @@ func TestInstanceReconciliation(t *testing.T) {
341
384
BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
342
385
},
343
386
AvailabilityDomain : common .String ("ad2" ),
387
+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
344
388
CompartmentId : common .String ("test" ),
345
389
IsPvEncryptionInTransitEnabled : common .Bool (true ),
346
390
DefinedTags : map [string ]map [string ]interface {}{},
@@ -379,6 +423,7 @@ func TestInstanceReconciliation(t *testing.T) {
379
423
},
380
424
Shape : common .String ("shape" ),
381
425
AvailabilityDomain : common .String ("ad2" ),
426
+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
382
427
CompartmentId : common .String ("test" ),
383
428
IsPvEncryptionInTransitEnabled : common .Bool (true ),
384
429
DefinedTags : map [string ]map [string ]interface {}{},
@@ -425,6 +470,7 @@ func TestInstanceReconciliation(t *testing.T) {
425
470
BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
426
471
},
427
472
AvailabilityDomain : common .String ("ad2" ),
473
+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
428
474
CompartmentId : common .String ("test" ),
429
475
IsPvEncryptionInTransitEnabled : common .Bool (true ),
430
476
DefinedTags : map [string ]map [string ]interface {}{},
@@ -473,6 +519,7 @@ func TestInstanceReconciliation(t *testing.T) {
473
519
BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
474
520
},
475
521
AvailabilityDomain : common .String ("ad2" ),
522
+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
476
523
CompartmentId : common .String ("test" ),
477
524
IsPvEncryptionInTransitEnabled : common .Bool (true ),
478
525
DefinedTags : map [string ]map [string ]interface {}{},
@@ -525,6 +572,7 @@ func TestInstanceReconciliation(t *testing.T) {
525
572
BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
526
573
},
527
574
AvailabilityDomain : common .String ("ad2" ),
575
+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
528
576
CompartmentId : common .String ("test" ),
529
577
IsPvEncryptionInTransitEnabled : common .Bool (true ),
530
578
DefinedTags : map [string ]map [string ]interface {}{},
@@ -578,6 +626,7 @@ func TestInstanceReconciliation(t *testing.T) {
578
626
BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
579
627
},
580
628
AvailabilityDomain : common .String ("ad2" ),
629
+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
581
630
CompartmentId : common .String ("test" ),
582
631
IsPvEncryptionInTransitEnabled : common .Bool (true ),
583
632
DefinedTags : map [string ]map [string ]interface {}{},
@@ -636,6 +685,30 @@ func instanceCompartmentIDMatcher(request interface{}, matchStr string) error {
636
685
return nil
637
686
}
638
687
688
+ func instanceFDMatcher (request interface {}, matchStr string ) error {
689
+ r , ok := request .(core.LaunchInstanceRequest )
690
+ if ! ok {
691
+ return errors .New ("expecting LaunchInstanceRequest type" )
692
+ }
693
+ if * r .LaunchInstanceDetails .FaultDomain != matchStr {
694
+ return errors .New (fmt .Sprintf ("expecting fd as %s" , matchStr ))
695
+ }
696
+ return nil
697
+ }
698
+
699
+ func anyFdMatcher (request interface {}) error {
700
+ r , ok := request .(core.LaunchInstanceRequest )
701
+ if ! ok {
702
+ return errors .New ("expecting LaunchInstanceRequest type" )
703
+ }
704
+ for _ , f := range fdList {
705
+ if f == * r .FaultDomain {
706
+ return nil
707
+ }
708
+ }
709
+ return errors .New (fmt .Sprintf ("invalid fd" ))
710
+ }
711
+
639
712
func TestLBReconciliationCreation (t * testing.T ) {
640
713
var (
641
714
ms * MachineScope
@@ -1304,6 +1377,7 @@ func setupAllParams(ms *MachineScope) {
1304
1377
"2" : {
1305
1378
Attributes : map [string ]string {
1306
1379
"AvailabilityDomain" : "ad2" ,
1380
+ "FaultDomain" : "FAULT-DOMAIN-2" ,
1307
1381
},
1308
1382
},
1309
1383
"3" : {
@@ -1312,6 +1386,17 @@ func setupAllParams(ms *MachineScope) {
1312
1386
},
1313
1387
},
1314
1388
}
1389
+ ms .OCICluster .Status .AvailabilityDomains = map [string ]infrastructurev1beta1.OCIAvailabilityDomain {
1390
+ "ad1" : {
1391
+ FaultDomains : fdList ,
1392
+ },
1393
+ "ad2" : {
1394
+ FaultDomains : fdList ,
1395
+ },
1396
+ "ad3" : {
1397
+ FaultDomains : fdList ,
1398
+ },
1399
+ }
1315
1400
ms .Machine .Spec .FailureDomain = common .String ("2" )
1316
1401
ms .OCICluster .Spec .NetworkSpec .Vcn .Subnets = []* infrastructurev1beta1.Subnet {
1317
1402
{
@@ -1323,3 +1408,13 @@ func setupAllParams(ms *MachineScope) {
1323
1408
ms .OCICluster .Spec .OCIResourceIdentifier = "resource_uid"
1324
1409
ms .OCIMachine .UID = "machineuid"
1325
1410
}
1411
+
1412
+ // The error built-in interface type is the conventional interface for
1413
+ // representing an error condition, with the nil value representing no error.
1414
+ type TestError struct {
1415
+ errorString string
1416
+ }
1417
+
1418
+ func (t TestError ) Error () string {
1419
+ return t .errorString
1420
+ }
0 commit comments