@@ -3,6 +3,7 @@ package linode
33import (
44 "context"
55 "encoding/json"
6+ "errors"
67 "fmt"
78 "net/http"
89 "os"
@@ -50,7 +51,7 @@ const (
5051)
5152
5253var (
53- errNoNodesAvailable = fmt . Errorf ("no nodes available for nodebalancer" )
54+ errNoNodesAvailable = errors . New ("no nodes available for nodebalancer" )
5455)
5556
5657type lbNotFoundError struct {
@@ -216,9 +217,6 @@ func (l *loadbalancers) GetLoadBalancer(ctx context.Context, clusterName string,
216217//
217218// EnsureLoadBalancer will not modify service or nodes.
218219func (l * loadbalancers ) EnsureLoadBalancer (ctx context.Context , clusterName string , service * v1.Service , nodes []* v1.Node ) (lbStatus * v1.LoadBalancerStatus , err error ) {
219- if len (nodes ) == 0 {
220- return nil , fmt .Errorf ("%w: cluster %s, service %s" , errNoNodesAvailable , clusterName , getServiceNn (service ))
221- }
222220 ctx = sentry .SetHubOnContext (ctx )
223221 sentry .SetTag (ctx , "cluster_name" , clusterName )
224222 sentry .SetTag (ctx , "service" , service .Name )
@@ -261,6 +259,10 @@ func (l *loadbalancers) EnsureLoadBalancer(ctx context.Context, clusterName stri
261259
262260//nolint:funlen
263261func (l * loadbalancers ) updateNodeBalancer (ctx context.Context , service * v1.Service , nodes []* v1.Node , nb * linodego.NodeBalancer ) (err error ) {
262+ if len (nodes ) == 0 {
263+ return fmt .Errorf ("%w: service %s" , errNoNodesAvailable , getServiceNn (service ))
264+ }
265+
264266 connThrottle := getConnectionThrottle (service )
265267 if connThrottle != nb .ClientConnThrottle {
266268 update := nb .GetUpdateOptions ()
@@ -349,9 +351,6 @@ func (l *loadbalancers) updateNodeBalancer(ctx context.Context, service *v1.Serv
349351
350352// UpdateLoadBalancer updates the NodeBalancer to have configs that match the Service's ports
351353func (l * loadbalancers ) UpdateLoadBalancer (ctx context.Context , clusterName string , service * v1.Service , nodes []* v1.Node ) (err error ) {
352- if len (nodes ) == 0 {
353- return fmt .Errorf ("%w: cluster %s, service %s" , errNoNodesAvailable , clusterName , getServiceNn (service ))
354- }
355354 ctx = sentry .SetHubOnContext (ctx )
356355 sentry .SetTag (ctx , "cluster_name" , clusterName )
357356 sentry .SetTag (ctx , "service" , service .Name )
@@ -594,6 +593,9 @@ func (l *loadbalancers) addTLSCert(ctx context.Context, service *v1.Service, nbC
594593// buildLoadBalancerRequest returns a linodego.NodeBalancer
595594// requests for service across nodes.
596595func (l * loadbalancers ) buildLoadBalancerRequest (ctx context.Context , clusterName string , service * v1.Service , nodes []* v1.Node ) (* linodego.NodeBalancer , error ) {
596+ if len (nodes ) == 0 {
597+ return nil , fmt .Errorf ("%w: cluster %s, service %s" , errNoNodesAvailable , clusterName , getServiceNn (service ))
598+ }
597599 ports := service .Spec .Ports
598600 configs := make ([]* linodego.NodeBalancerConfigCreateOptions , 0 , len (ports ))
599601
0 commit comments