@@ -245,7 +245,7 @@ var _ = Describe("LoadBalancer", func() {
245
245
loadBalancerIP string
246
246
)
247
247
248
- BeforeAll (func () {
248
+ BeforeEach (func () {
249
249
ctrl , ctx = gomock .WithContext (context .Background (), GinkgoT ())
250
250
c = mockclient .NewMockClient (ctrl )
251
251
lb = & loadbalancer {
@@ -402,6 +402,68 @@ var _ = Describe("LoadBalancer", func() {
402
402
403
403
})
404
404
405
+ It ("Should create new Service without selector if selectorless flag is true" , func () {
406
+ checkSvcExistErr := notFoundErr
407
+ getCount := 1
408
+ port := 30001
409
+ infraServiceExist := generateInfraService (
410
+ tenantService ,
411
+ []corev1.ServicePort {
412
+ {Name : "port1" , Protocol : corev1 .ProtocolTCP , Port : 80 , TargetPort : intstr.IntOrString {Type : intstr .Int , IntVal : int32 (port )}},
413
+ },
414
+ )
415
+ infraServiceExist .Status = corev1.ServiceStatus {
416
+ LoadBalancer : corev1.LoadBalancerStatus {
417
+ Ingress : []corev1.LoadBalancerIngress {
418
+ {
419
+ IP : loadBalancerIP ,
420
+ },
421
+ },
422
+ },
423
+ }
424
+
425
+ c .EXPECT ().
426
+ Get (ctx , client.ObjectKey {Name : "af6ebf1722bb111e9b210d663bd873d9" , Namespace : "test" }, gomock .AssignableToTypeOf (& corev1.Service {})).
427
+ Return (checkSvcExistErr )
428
+
429
+ infraService1 := generateInfraService (
430
+ tenantService ,
431
+ []corev1.ServicePort {
432
+ {Name : "port1" , Protocol : corev1 .ProtocolTCP , Port : 80 , TargetPort : intstr.IntOrString {Type : intstr .Int , IntVal : 30001 }},
433
+ },
434
+ )
435
+ infraService1 .Spec .Selector = nil
436
+
437
+ c .EXPECT ().Create (ctx , infraService1 )
438
+
439
+ for i := 0 ; i < getCount ; i ++ {
440
+ infraService2 := infraService1 .DeepCopy ()
441
+ if i == getCount - 1 {
442
+ infraService2 .Status = corev1.ServiceStatus {
443
+ LoadBalancer : corev1.LoadBalancerStatus {
444
+ Ingress : []corev1.LoadBalancerIngress {
445
+ {
446
+ IP : loadBalancerIP ,
447
+ },
448
+ },
449
+ },
450
+ }
451
+ }
452
+ c .EXPECT ().Get (
453
+ ctx ,
454
+ client.ObjectKey {Name : "af6ebf1722bb111e9b210d663bd873d9" , Namespace : "test" },
455
+ gomock .AssignableToTypeOf (& corev1.Service {}),
456
+ ).Do (func (ctx context.Context , key client.ObjectKey , obj client.Object , opts ... client.GetOption ) {
457
+ infraService2 .DeepCopyInto (obj .(* corev1.Service ))
458
+ })
459
+ }
460
+ lb .config .Selectorless = pointer .Bool (true )
461
+ lbStatus , err := lb .EnsureLoadBalancer (ctx , clusterName , tenantService , nodes )
462
+ Expect (err ).To (BeNil ())
463
+ Expect (len (lbStatus .Ingress )).Should (Equal (1 ))
464
+ Expect (lbStatus .Ingress [0 ].IP ).Should (Equal (loadBalancerIP ))
465
+
466
+ })
405
467
It ("Should return an error if service already exist" , func () {
406
468
expectedError := errors .New ("Test error - check if service already exist" )
407
469
port := 30001
0 commit comments