From 2a5a12150512c9e316a3020e86a3ad9b9eb06591 Mon Sep 17 00:00:00 2001 From: Alex Robinson Date: Fri, 9 Oct 2015 17:27:28 +0000 Subject: [PATCH] Fix small comments. --- pkg/cloudprovider/providers/gce/gce.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/cloudprovider/providers/gce/gce.go b/pkg/cloudprovider/providers/gce/gce.go index 9e5cd5c5607..f1244a10bf7 100644 --- a/pkg/cloudprovider/providers/gce/gce.go +++ b/pkg/cloudprovider/providers/gce/gce.go @@ -400,8 +400,9 @@ func (gce *GCECloud) EnsureTCPLoadBalancer(name, region string, requestedIP net. return nil, fmt.Errorf("failed to delete existing forwarding rule %s for load balancer update: %v", name, err) } if deleteFwdRuleIP { - // Delete the old IP to avoid leaking it, since we're going to be using - // the user-requested IP when recreating the forwarding rule below. + // Delete the old forwarding rule's IP to avoid leaking it, since we're + // going to be using the user-requested IP when recreating the forwarding + // rule below. gce.deleteStaticIP(name, region) } } @@ -429,6 +430,10 @@ func (gce *GCECloud) EnsureTCPLoadBalancer(name, region string, requestedIP net. return status, nil } +// Passing nil for requested IP is perfectly fine - it just means that no specific +// IP is being requested. +// Returns whether the forwarding rule exists, whether it needs to be updated, +// what its IP address is (if it exists), and any error we encountered. func (gce *GCECloud) forwardingRuleNeedsUpdate(name, region string, requestedIP net.IP, ports []*api.ServicePort) (exists bool, needsUpdate bool, ipAddress string, err error) { fwd, err := gce.service.ForwardingRules.Get(gce.projectID, region, name).Do() if err != nil { @@ -507,13 +512,10 @@ func (gce *GCECloud) firewallNeedsUpdate(name, region, ipAddress string, ports [ if fw.Description != makeFirewallDescription(ipAddress) { return true, true, nil } - // Make sure the allowed ports match - if len(fw.Allowed) != 1 { - return true, true, nil - } - if fw.Allowed[0].IPProtocol != "tcp" { + if len(fw.Allowed) != 1 || fw.Allowed[0].IPProtocol != "tcp" { return true, true, nil } + // Make sure the allowed ports match. allowedPorts := make([]string, len(ports)) for ix := range ports { allowedPorts[ix] = strconv.Itoa(ports[ix].Port) @@ -624,7 +626,7 @@ func (gce *GCECloud) updateFirewall(name, region, ipAddress string, ports []*api } if op != nil { err = gce.waitForGlobalOp(op) - if err != nil && !isHTTPErrorCode(err, http.StatusConflict) { + if err != nil { return err } }