Skip to content

Commit

Permalink
Add test for NodeBalancer port configuration annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
thorner committed Mar 5, 2020
1 parent edf7047 commit c6e8a2e
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions cloud/linode/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,80 @@ func testUpdateLoadBalancerAddAnnotation(t *testing.T, client *linodego.Client)
}
}

func testUpdateLoadBalancerAddPortAnnotation(t *testing.T, client *linodego.Client) {
targetTestPort := 80
portConfigAnnotation = fmt.Sprintf("%s-%i", annLinodePortConfigPrefix, targetTestPort)
svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: randString(10),
UID: "foobar123",
Annotations: map[string]string{
annLinodeDefaultProtocol: "tcp",
},
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
{
Name: randString(10),
Protocol: "TCP",
Port: int32(80),
NodePort: int32(30000),
},
},
},
}

nodes := []*v1.Node{
&v1.Node{
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{
Type: v1.NodeInternalIP,
Address: "127.0.0.1",
},
},
},
},
}

lb := &loadbalancers{client, "us-west", nil}

defer lb.EnsureLoadBalancerDeleted(context.TODO(), "lnodelb", svc)

_, err := lb.EnsureLoadBalancer(context.TODO(), "lnodelb", svc, nodes)
if err != nil {
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
}

svc.ObjectMeta.SetAnnotations(map[string]string{
portConfigAnnotation: "http",
})

err = lb.UpdateLoadBalancer(context.TODO(), "lnodelb", svc, nodes)
if err != nil {
t.Errorf("UpdateLoadBalancer returned an error while updated annotations: %s", err)
}

lbName := cloudprovider.GetLoadBalancerName(svc)
nb, err := lb.lbByName(context.TODO(), lb.client, lbName)
if err != nil {
t.Errorf("unexpected error: %v", err)
}

cfgs, errConfigs := client.ListNodeBalancerConfigs(context.TODO(), nb.ID, nil)
if errConfigs != nil {
t.Errorf("error getting NodeBalancer configs: %v", errConfigs)
}

expectedPortConfig := (targetTestPort, "http")
for _, cfg := range cfgs {
observedPortConfig := (cfg.Port, cfg.Protocol)
if !reflect.DeepEqual(expectedPortConfig, observedPortConfig) {
t.Errorf("expected port protcol: expected %v, got %v", "http", cfg.Protocol)
}
}
}

func testUpdateLoadBalancerAddPort(t *testing.T, client *linodego.Client) {
svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit c6e8a2e

Please sign in to comment.