@@ -177,6 +177,7 @@ func TestLoadBalancers_EnsureLoadBalancer(t *testing.T) {
177
177
178
178
balancerName := "service-cluster-a123"
179
179
locationID := int64 (1 )
180
+ sharedCluster := true
180
181
181
182
balancer := cli.LoadBalancer {
182
183
ID : "a" ,
@@ -193,7 +194,8 @@ func TestLoadBalancers_EnsureLoadBalancer(t *testing.T) {
193
194
ctx := context .TODO ()
194
195
195
196
input := cli.L4LoadBalancerUpdateInput {
196
- Name : & balancerName ,
197
+ Name : & balancerName ,
198
+ SharedCluster : & sharedCluster ,
197
199
VHostZones : []cli.L4VHostZoneInput {
198
200
{
199
201
ID : "k8s-nodes-80-tcp" ,
@@ -351,12 +353,12 @@ func TestLoadBalancers_EnsureLoadBalancerWithCreate(t *testing.T) {
351
353
},
352
354
}
353
355
354
- collection .EXPECT ().SetPerPage (100 ).Return (collection )
355
- collection .EXPECT ().SetParam ("search_pattern" , balancerName ).Return (collection )
356
- collection .EXPECT ().SetParam ("type" , "l4" ).Return (collection )
357
- collection .EXPECT ().Collect (ctx ).Return ([]cli.LoadBalancer {}, nil )
356
+ collection .EXPECT ().SetPerPage (100 ).Return (collection ). Times ( 2 )
357
+ collection .EXPECT ().SetParam ("search_pattern" , balancerName ).Return (collection ). Times ( 2 )
358
+ collection .EXPECT ().SetParam ("type" , "l4" ).Return (collection ). Times ( 2 )
359
+ collection .EXPECT ().Collect (ctx ).Return ([]cli.LoadBalancer {}, nil ). Times ( 2 )
358
360
359
- service .EXPECT ().Collection ().Return (collection )
361
+ service .EXPECT ().Collection ().Return (collection ). Times ( 2 )
360
362
service .EXPECT ().CreateL4LoadBalancer (ctx , input ).Return (& l4Balancer , nil )
361
363
362
364
client := cli .NewClient ("some" )
@@ -381,6 +383,19 @@ func TestLoadBalancers_EnsureLoadBalancerWithCreate(t *testing.T) {
381
383
382
384
g .Expect (err ).To (BeNil ())
383
385
g .Expect (status ).NotTo (BeNil ())
386
+
387
+ // with cluster-id annotation
388
+ clusterID := "some-hash-id"
389
+ srv .Annotations = map [string ]string {
390
+ "servers.com/cluster-id" : clusterID ,
391
+ }
392
+
393
+ input .ClusterID = & clusterID
394
+ service .EXPECT ().CreateL4LoadBalancer (ctx , input ).Return (& l4Balancer , nil )
395
+ status , err = balancerInterface .EnsureLoadBalancer (ctx , "cluster" , & srv , []* v1.Node {& node })
396
+
397
+ g .Expect (err ).To (BeNil ())
398
+ g .Expect (status ).NotTo (BeNil ())
384
399
}
385
400
386
401
func TestLoadBalancers_UpdateLoadBalancer (t * testing.T ) {
@@ -394,6 +409,7 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
394
409
395
410
balancerName := "service-cluster-a123"
396
411
locationID := int64 (1 )
412
+ sharedCluster := true
397
413
398
414
balancer := cli.LoadBalancer {
399
415
ID : "a" ,
@@ -410,7 +426,8 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
410
426
ctx := context .TODO ()
411
427
412
428
input := cli.L4LoadBalancerUpdateInput {
413
- Name : & balancerName ,
429
+ Name : & balancerName ,
430
+ SharedCluster : & sharedCluster ,
414
431
VHostZones : []cli.L4VHostZoneInput {
415
432
{
416
433
ID : "k8s-nodes-80-tcp" ,
@@ -461,13 +478,13 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
461
478
},
462
479
}
463
480
464
- collection .EXPECT ().SetPerPage (100 ).Return (collection )
465
- collection .EXPECT ().SetParam ("search_pattern" , balancerName ).Return (collection )
466
- collection .EXPECT ().SetParam ("type" , "l4" ).Return (collection )
467
- collection .EXPECT ().Collect (ctx ).Return ([]cli.LoadBalancer {balancer }, nil )
481
+ collection .EXPECT ().SetPerPage (100 ).Return (collection ). Times ( 2 )
482
+ collection .EXPECT ().SetParam ("search_pattern" , balancerName ).Return (collection ). Times ( 2 )
483
+ collection .EXPECT ().SetParam ("type" , "l4" ).Return (collection ). Times ( 2 )
484
+ collection .EXPECT ().Collect (ctx ).Return ([]cli.LoadBalancer {balancer }, nil ). Times ( 2 )
468
485
469
- service .EXPECT ().Collection ().Return (collection )
470
- service .EXPECT ().GetL4LoadBalancer (ctx , "a" ).Return (& l4Balancer , nil )
486
+ service .EXPECT ().Collection ().Return (collection ). Times ( 2 )
487
+ service .EXPECT ().GetL4LoadBalancer (ctx , "a" ).Return (& l4Balancer , nil ). Times ( 2 )
471
488
service .EXPECT ().UpdateL4LoadBalancer (ctx , "a" , input ).Return (& l4Balancer , nil )
472
489
473
490
client := cli .NewClient ("some" )
@@ -492,6 +509,20 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
492
509
493
510
g .Expect (err ).To (BeNil ())
494
511
g .Expect (status ).NotTo (BeNil ())
512
+
513
+ // with cluster-id annotation
514
+ clusterID := "some-hash-id"
515
+ srv .Annotations = map [string ]string {
516
+ "servers.com/cluster-id" : clusterID ,
517
+ }
518
+
519
+ input .ClusterID = & clusterID
520
+ input .SharedCluster = nil
521
+ service .EXPECT ().UpdateL4LoadBalancer (ctx , "a" , input ).Return (& l4Balancer , nil )
522
+ status , err = balancerInterface .EnsureLoadBalancer (ctx , "cluster" , & srv , []* v1.Node {& node })
523
+
524
+ g .Expect (err ).To (BeNil ())
525
+ g .Expect (status ).NotTo (BeNil ())
495
526
}
496
527
497
528
func TestLoadBalancers_EnsureLoadBalancerDeleted (t * testing.T ) {
0 commit comments