@@ -2,6 +2,7 @@ package linode
22
33import (
44 "context"
5+ stderrors "errors"
56 "fmt"
67 "net/http"
78 "net/http/httptest"
@@ -180,6 +181,10 @@ func TestCCMLoadBalancers(t *testing.T) {
180181 name : "Cleanup does not call the API unless Service annotated" ,
181182 f : testCleanupDoesntCall ,
182183 },
184+ {
185+ name : "Update Load Balancer - No Nodes" ,
186+ f : testUpdateLoadBalancerNoNodes ,
187+ },
183188 }
184189
185190 for _ , tc := range testCases {
@@ -229,7 +234,9 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) {
229234 }
230235
231236 lb := & loadbalancers {client , "us-west" , nil }
232- var nodes []* v1.Node
237+ nodes := []* v1.Node {
238+ {ObjectMeta : metav1.ObjectMeta {Name : "node-1" }},
239+ }
233240 nb , err := lb .buildLoadBalancerRequest (context .TODO (), "linodelb" , svc , nodes )
234241 if err != nil {
235242 t .Fatal (err )
@@ -1631,6 +1638,55 @@ func testCleanupDoesntCall(t *testing.T, client *linodego.Client, fakeAPI *fakeA
16311638 })
16321639}
16331640
1641+ func testUpdateLoadBalancerNoNodes (t * testing.T , client * linodego.Client , _ * fakeAPI ) {
1642+ svc := & v1.Service {
1643+ ObjectMeta : metav1.ObjectMeta {
1644+ Name : randString (10 ),
1645+ UID : "foobar123" ,
1646+ Annotations : map [string ]string {},
1647+ },
1648+ Spec : v1.ServiceSpec {
1649+ Ports : []v1.ServicePort {
1650+ {
1651+ Name : randString (10 ),
1652+ Protocol : "http" ,
1653+ Port : int32 (80 ),
1654+ NodePort : int32 (8080 ),
1655+ },
1656+ },
1657+ },
1658+ }
1659+
1660+ lb := & loadbalancers {client , "us-west" , nil }
1661+ defer lb .EnsureLoadBalancerDeleted (context .TODO (), "linodelb" , svc )
1662+
1663+ fakeClientset := fake .NewSimpleClientset ()
1664+ lb .kubeClient = fakeClientset
1665+
1666+ nodeBalancer , err := client .CreateNodeBalancer (context .TODO (), linodego.NodeBalancerCreateOptions {
1667+ Region : lb .zone ,
1668+ })
1669+ if err != nil {
1670+ t .Fatalf ("failed to create NodeBalancer: %s" , err )
1671+ }
1672+ svc .Status .LoadBalancer = * makeLoadBalancerStatus (svc , nodeBalancer )
1673+ stubService (fakeClientset , svc )
1674+ svc .ObjectMeta .SetAnnotations (map [string ]string {
1675+ annLinodeNodeBalancerID : strconv .Itoa (nodeBalancer .ID ),
1676+ })
1677+
1678+ // setup done, test ensure/update
1679+ nodes := []* v1.Node {}
1680+
1681+ if _ , err = lb .EnsureLoadBalancer (context .TODO (), "linodelb" , svc , nodes ); ! stderrors .Is (err , errNoNodesAvailable ) {
1682+ t .Errorf ("EnsureLoadBalancer should return %v, got %v" , errNoNodesAvailable , err )
1683+ }
1684+
1685+ if err := lb .UpdateLoadBalancer (context .TODO (), "linodelb" , svc , nodes ); ! stderrors .Is (err , errNoNodesAvailable ) {
1686+ t .Errorf ("UpdateLoadBalancer should return %v, got %v" , errNoNodesAvailable , err )
1687+ }
1688+ }
1689+
16341690func testGetNodeBalancerForServiceIDDoesNotExist (t * testing.T , client * linodego.Client , _ * fakeAPI ) {
16351691 lb := & loadbalancers {client , "us-west" , nil }
16361692 bogusNodeBalancerID := "123456"
0 commit comments