@@ -177,6 +177,7 @@ func TestLoadBalancers_EnsureLoadBalancer(t *testing.T) {
177177
178178 balancerName := "service-cluster-a123"
179179 locationID := int64 (1 )
180+ sharedCluster := true
180181
181182 balancer := cli.LoadBalancer {
182183 ID : "a" ,
@@ -193,7 +194,8 @@ func TestLoadBalancers_EnsureLoadBalancer(t *testing.T) {
193194 ctx := context .TODO ()
194195
195196 input := cli.L4LoadBalancerUpdateInput {
196- Name : & balancerName ,
197+ Name : & balancerName ,
198+ SharedCluster : & sharedCluster ,
197199 VHostZones : []cli.L4VHostZoneInput {
198200 {
199201 ID : "k8s-nodes-80-tcp" ,
@@ -351,12 +353,12 @@ func TestLoadBalancers_EnsureLoadBalancerWithCreate(t *testing.T) {
351353 },
352354 }
353355
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 )
358360
359- service .EXPECT ().Collection ().Return (collection )
361+ service .EXPECT ().Collection ().Return (collection ). Times ( 2 )
360362 service .EXPECT ().CreateL4LoadBalancer (ctx , input ).Return (& l4Balancer , nil )
361363
362364 client := cli .NewClient ("some" )
@@ -381,6 +383,19 @@ func TestLoadBalancers_EnsureLoadBalancerWithCreate(t *testing.T) {
381383
382384 g .Expect (err ).To (BeNil ())
383385 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 ())
384399}
385400
386401func TestLoadBalancers_UpdateLoadBalancer (t * testing.T ) {
@@ -394,6 +409,7 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
394409
395410 balancerName := "service-cluster-a123"
396411 locationID := int64 (1 )
412+ sharedCluster := true
397413
398414 balancer := cli.LoadBalancer {
399415 ID : "a" ,
@@ -410,7 +426,8 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
410426 ctx := context .TODO ()
411427
412428 input := cli.L4LoadBalancerUpdateInput {
413- Name : & balancerName ,
429+ Name : & balancerName ,
430+ SharedCluster : & sharedCluster ,
414431 VHostZones : []cli.L4VHostZoneInput {
415432 {
416433 ID : "k8s-nodes-80-tcp" ,
@@ -461,13 +478,13 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
461478 },
462479 }
463480
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 )
468485
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 )
471488 service .EXPECT ().UpdateL4LoadBalancer (ctx , "a" , input ).Return (& l4Balancer , nil )
472489
473490 client := cli .NewClient ("some" )
@@ -492,6 +509,20 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
492509
493510 g .Expect (err ).To (BeNil ())
494511 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 ())
495526}
496527
497528func TestLoadBalancers_EnsureLoadBalancerDeleted (t * testing.T ) {
0 commit comments