From cb7d3f01485d26679ca1d69adaf90c20aebbf2d3 Mon Sep 17 00:00:00 2001 From: CJ Cullen Date: Fri, 28 Aug 2015 15:36:46 -0700 Subject: [PATCH] Return an error from gce.EnsureTCPLoadBalancer with no hosts. --- pkg/cloudprovider/providers/gce/gce.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/cloudprovider/providers/gce/gce.go b/pkg/cloudprovider/providers/gce/gce.go index 302ca903348..e5a1bb3ead8 100644 --- a/pkg/cloudprovider/providers/gce/gce.go +++ b/pkg/cloudprovider/providers/gce/gce.go @@ -352,7 +352,11 @@ func makeFirewallName(name string) string { // TODO(a-robinson): Don't just ignore specified IP addresses. Check if they're // owned by the project and available to be used, and use them if they are. func (gce *GCECloud) EnsureTCPLoadBalancer(name, region string, externalIP net.IP, ports []*api.ServicePort, hosts []string, affinityType api.ServiceAffinity) (*api.LoadBalancerStatus, error) { - glog.V(2).Info("Checking if load balancer already exists: %s", name) + if len(hosts) == 0 { + return nil, fmt.Errorf("Cannot EnsureTCPLoadBalancer() with no hosts") + } + + glog.V(2).Infof("Checking if load balancer already exists: %s", name) _, exists, err := gce.GetTCPLoadBalancer(name, region) if err != nil { return nil, fmt.Errorf("error checking if GCE load balancer already exists: %v", err)