@@ -150,6 +150,10 @@ func TestCCMLoadBalancers(t *testing.T) {
150150 name : "Create Load Balancer With Invalid Firewall ACL - NO Allow Or Deny" ,
151151 f : testCreateNodeBalanceWithNoAllowOrDenyList ,
152152 },
153+ {
154+ name : "Create Load Balancer With Global Tags set" ,
155+ f : testCreateNodeBalancerWithGlobalTags ,
156+ },
153157 {
154158 name : "Update Load Balancer - Add Node" ,
155159 f : testUpdateLoadBalancerAddNode ,
@@ -274,7 +278,7 @@ func stubService(fake *fake.Clientset, service *v1.Service) {
274278 _ , _ = fake .CoreV1 ().Services ("" ).Create (context .TODO (), service , metav1.CreateOptions {})
275279}
276280
277- func testCreateNodeBalancer (t * testing.T , client * linodego.Client , _ * fakeAPI , annMap map [string ]string ) error {
281+ func testCreateNodeBalancer (t * testing.T , client * linodego.Client , _ * fakeAPI , annMap map [string ]string , expectedTags [] string ) error {
278282 svc := & v1.Service {
279283 ObjectMeta : metav1.ObjectMeta {
280284 Name : randString (),
@@ -341,7 +345,9 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI, a
341345 t .Logf ("actual: %v" , nb .ClientConnThrottle )
342346 }
343347
344- expectedTags := []string {"linodelb" , "fake" , "test" , "yolo" }
348+ if len (expectedTags ) == 0 {
349+ expectedTags = []string {"linodelb" , "fake" , "test" , "yolo" }
350+ }
345351 if ! reflect .DeepEqual (nb .Tags , expectedTags ) {
346352 t .Error ("unexpected Tags" )
347353 t .Logf ("expected: %v" , expectedTags )
@@ -366,7 +372,7 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI, a
366372}
367373
368374func testCreateNodeBalancerWithOutFirewall (t * testing.T , client * linodego.Client , f * fakeAPI ) {
369- err := testCreateNodeBalancer (t , client , f , nil )
375+ err := testCreateNodeBalancer (t , client , f , nil , nil )
370376 if err != nil {
371377 t .Fatalf ("expected a nil error, got %v" , err )
372378 }
@@ -377,7 +383,7 @@ func testCreateNodeBalanceWithNoAllowOrDenyList(t *testing.T, client *linodego.C
377383 annotations .AnnLinodeCloudFirewallACL : `{}` ,
378384 }
379385
380- err := testCreateNodeBalancer (t , client , f , annotations )
386+ err := testCreateNodeBalancer (t , client , f , annotations , nil )
381387 if err == nil || ! stderrors .Is (err , firewall .ErrInvalidFWConfig ) {
382388 t .Fatalf ("expected a %v error, got %v" , firewall .ErrInvalidFWConfig , err )
383389 }
@@ -395,7 +401,7 @@ func testCreateNodeBalanceWithBothAllowOrDenyList(t *testing.T, client *linodego
395401 }` ,
396402 }
397403
398- err := testCreateNodeBalancer (t , client , f , annotations )
404+ err := testCreateNodeBalancer (t , client , f , annotations , nil )
399405 if err == nil || ! stderrors .Is (err , firewall .ErrInvalidFWConfig ) {
400406 t .Fatalf ("expected a %v error, got %v" , firewall .ErrInvalidFWConfig , err )
401407 }
@@ -410,7 +416,7 @@ func testCreateNodeBalancerWithAllowList(t *testing.T, client *linodego.Client,
410416 }` ,
411417 }
412418
413- err := testCreateNodeBalancer (t , client , f , annotations )
419+ err := testCreateNodeBalancer (t , client , f , annotations , nil )
414420 if err != nil {
415421 t .Fatalf ("expected a non-nil error, got %v" , err )
416422 }
@@ -425,7 +431,7 @@ func testCreateNodeBalancerWithDenyList(t *testing.T, client *linodego.Client, f
425431 }` ,
426432 }
427433
428- err := testCreateNodeBalancer (t , client , f , annotations )
434+ err := testCreateNodeBalancer (t , client , f , annotations , nil )
429435 if err != nil {
430436 t .Fatalf ("expected a non-nil error, got %v" , err )
431437 }
@@ -435,7 +441,7 @@ func testCreateNodeBalancerWithFirewall(t *testing.T, client *linodego.Client, f
435441 annotations := map [string ]string {
436442 annotations .AnnLinodeCloudFirewallID : "123" ,
437443 }
438- err := testCreateNodeBalancer (t , client , f , annotations )
444+ err := testCreateNodeBalancer (t , client , f , annotations , nil )
439445 if err != nil {
440446 t .Fatalf ("expected a nil error, got %v" , err )
441447 }
@@ -446,12 +452,25 @@ func testCreateNodeBalancerWithInvalidFirewall(t *testing.T, client *linodego.Cl
446452 annotations .AnnLinodeCloudFirewallID : "qwerty" ,
447453 }
448454 expectedError := "strconv.Atoi: parsing \" qwerty\" : invalid syntax"
449- err := testCreateNodeBalancer (t , client , f , annotations )
455+ err := testCreateNodeBalancer (t , client , f , annotations , nil )
450456 if err .Error () != expectedError {
451457 t .Fatalf ("expected a %s error, got %v" , expectedError , err )
452458 }
453459}
454460
461+ func testCreateNodeBalancerWithGlobalTags (t * testing.T , client * linodego.Client , f * fakeAPI ) {
462+ original := Options .NodeBalancerTags
463+ defer func () {
464+ Options .NodeBalancerTags = original
465+ }()
466+ Options .NodeBalancerTags = []string {"foobar" }
467+ expectedTags := []string {"linodelb" , "foobar" , "fake" , "test" , "yolo" }
468+ err := testCreateNodeBalancer (t , client , f , nil , expectedTags )
469+ if err != nil {
470+ t .Fatalf ("expected a nil error, got %v" , err )
471+ }
472+ }
473+
455474func testUpdateLoadBalancerAddNode (t * testing.T , client * linodego.Client , f * fakeAPI ) {
456475 svc := & v1.Service {
457476 ObjectMeta : metav1.ObjectMeta {
0 commit comments