|
8 | 8 | "os" |
9 | 9 | "reflect" |
10 | 10 | "strconv" |
| 11 | + "strings" |
11 | 12 | "testing" |
12 | 13 |
|
13 | 14 | "github.com/linode/linodego" |
@@ -127,6 +128,10 @@ func TestCCMLoadBalancers(t *testing.T) { |
127 | 128 | name: "Update Load Balancer - Add TLS Port", |
128 | 129 | f: testUpdateLoadBalancerAddTLSPort, |
129 | 130 | }, |
| 131 | + { |
| 132 | + name: "Update Load Balancer - Add Tags", |
| 133 | + f: testUpdateLoadBalancerAddTags, |
| 134 | + }, |
130 | 135 | { |
131 | 136 | name: "Update Load Balancer - Specify NodeBalancerID", |
132 | 137 | f: testUpdateLoadBalancerAddNodeBalancerID, |
@@ -201,7 +206,8 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) { |
201 | 206 | Name: randString(10), |
202 | 207 | UID: "foobar123", |
203 | 208 | Annotations: map[string]string{ |
204 | | - annLinodeThrottle: "15", |
| 209 | + annLinodeThrottle: "15", |
| 210 | + annLinodeLoadBalancerTags: "fake,test,yolo", |
205 | 211 | }, |
206 | 212 | }, |
207 | 213 | Spec: v1.ServiceSpec{ |
@@ -264,6 +270,13 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) { |
264 | 270 | t.Logf("actual: %v", nb.ClientConnThrottle) |
265 | 271 | } |
266 | 272 |
|
| 273 | + expectedTags := []string{"fake", "test", "yolo"} |
| 274 | + if !reflect.DeepEqual(nb.Tags, expectedTags) { |
| 275 | + t.Error("unexpected Tags") |
| 276 | + t.Logf("expected: %v", expectedTags) |
| 277 | + t.Logf("actual: %v", nb.Tags) |
| 278 | + } |
| 279 | + |
267 | 280 | defer func() { _ = lb.EnsureLoadBalancerDeleted(context.TODO(), "linodelb", svc) }() |
268 | 281 | } |
269 | 282 |
|
@@ -415,6 +428,74 @@ func testUpdateLoadBalancerAddPortAnnotation(t *testing.T, client *linodego.Clie |
415 | 428 | } |
416 | 429 | } |
417 | 430 |
|
| 431 | +func testUpdateLoadBalancerAddTags(t *testing.T, client *linodego.Client, _ *fakeAPI) { |
| 432 | + svc := &v1.Service{ |
| 433 | + ObjectMeta: metav1.ObjectMeta{ |
| 434 | + Name: randString(10), |
| 435 | + UID: "foobar123", |
| 436 | + Annotations: map[string]string{}, |
| 437 | + }, |
| 438 | + Spec: v1.ServiceSpec{ |
| 439 | + Ports: []v1.ServicePort{ |
| 440 | + { |
| 441 | + Name: randString(10), |
| 442 | + Protocol: "TCP", |
| 443 | + Port: int32(80), |
| 444 | + NodePort: int32(30000), |
| 445 | + }, |
| 446 | + }, |
| 447 | + }, |
| 448 | + } |
| 449 | + |
| 450 | + nodes := []*v1.Node{ |
| 451 | + &v1.Node{ |
| 452 | + Status: v1.NodeStatus{ |
| 453 | + Addresses: []v1.NodeAddress{ |
| 454 | + { |
| 455 | + Type: v1.NodeInternalIP, |
| 456 | + Address: "127.0.0.1", |
| 457 | + }, |
| 458 | + }, |
| 459 | + }, |
| 460 | + }, |
| 461 | + } |
| 462 | + |
| 463 | + lb := &loadbalancers{client, "us-west", nil} |
| 464 | + fakeClientset := fake.NewSimpleClientset() |
| 465 | + lb.kubeClient = fakeClientset |
| 466 | + |
| 467 | + defer lb.EnsureLoadBalancerDeleted(context.TODO(), "linodelb", svc) |
| 468 | + |
| 469 | + lbStatus, err := lb.EnsureLoadBalancer(context.TODO(), "linodelb", svc, nodes) |
| 470 | + if err != nil { |
| 471 | + t.Errorf("EnsureLoadBalancer returned an error: %s", err) |
| 472 | + } |
| 473 | + svc.Status.LoadBalancer = *lbStatus |
| 474 | + stubService(fakeClientset, svc) |
| 475 | + |
| 476 | + testTags := "test,new,tags" |
| 477 | + svc.ObjectMeta.SetAnnotations(map[string]string{ |
| 478 | + annLinodeLoadBalancerTags: testTags, |
| 479 | + }) |
| 480 | + |
| 481 | + err = lb.UpdateLoadBalancer(context.TODO(), "linodelb", svc, nodes) |
| 482 | + if err != nil { |
| 483 | + t.Fatalf("UpdateLoadBalancer returned an error while updated annotations: %s", err) |
| 484 | + } |
| 485 | + |
| 486 | + nb, err := lb.getNodeBalancerByStatus(context.TODO(), svc) |
| 487 | + if err != nil { |
| 488 | + t.Fatalf("failed to get NodeBalancer by status: %v", err) |
| 489 | + } |
| 490 | + |
| 491 | + expectedTags := strings.Split(testTags, ",") |
| 492 | + observedTags := nb.Tags |
| 493 | + |
| 494 | + if !reflect.DeepEqual(expectedTags, observedTags) { |
| 495 | + t.Errorf("NodeBalancer tags mismatch: expected %v, got %v", expectedTags, observedTags) |
| 496 | + } |
| 497 | +} |
| 498 | + |
418 | 499 | func testUpdateLoadBalancerAddTLSPort(t *testing.T, client *linodego.Client, _ *fakeAPI) { |
419 | 500 | svc := &v1.Service{ |
420 | 501 | ObjectMeta: metav1.ObjectMeta{ |
|
0 commit comments