// EnsureTCPLoadBalancerDeleted is an implementation of TCPLoadBalancer.EnsureTCPLoadBalancerDeleted. func (gce *GCECloud) EnsureTCPLoadBalancerDeleted(name, region string) error { err := errors.AggregateGoroutines( func() error { return gce.deleteFirewall(name, region) }, func() error { if err := gce.deleteForwardingRule(name, region); err != nil { return err } // The forwarding rule must be deleted before either the target pool or // static IP address can, unfortunately. err := errors.AggregateGoroutines( func() error { return gce.deleteTargetPool(name, region) }, func() error { return gce.deleteStaticIP(name, region) }, ) if err != nil { return err } return nil }, ) if err != nil { return errors.Flatten(err) } return nil }
// EnsureTCPLoadBalancerDeleted is an implementation of TCPLoadBalancer.EnsureTCPLoadBalancerDeleted. func (gce *GCECloud) EnsureTCPLoadBalancerDeleted(name, region string) error { err := errors.AggregateGoroutines( func() error { return gce.deleteFirewall(name, region) }, // Even though we don't hold on to static IPs for load balancers, it's // possible that EnsureTCPLoadBalancer left one around in a failed // creation/update attempt, so make sure we clean it up here just in case. func() error { return gce.deleteStaticIP(name, region) }, func() error { // The forwarding rule must be deleted before either the target pool can, // unfortunately, so we have to do these two serially. if err := gce.deleteForwardingRule(name, region); err != nil { return err } if err := gce.deleteTargetPool(name, region); err != nil { return err } return nil }, ) if err != nil { return errors.Flatten(err) } return nil }
// EnsureLoadBalancer creates a new load balancer 'name', or updates the existing one. Returns the status of the balancer func (az *Cloud) EnsureLoadBalancer(clusterName string, service *v1.Service, nodeNames []string) (*v1.LoadBalancerStatus, error) { lbName := getLoadBalancerName(clusterName) pipName := getPublicIPName(clusterName, service) serviceName := getServiceName(service) glog.V(2).Infof("ensure(%s): START clusterName=%q lbName=%q", serviceName, clusterName, lbName) pip, err := az.ensurePublicIPExists(serviceName, pipName) if err != nil { return nil, err } sg, err := az.SecurityGroupsClient.Get(az.ResourceGroup, az.SecurityGroupName, "") if err != nil { return nil, err } sg, sgNeedsUpdate, err := az.reconcileSecurityGroup(sg, clusterName, service) if err != nil { return nil, err } if sgNeedsUpdate { glog.V(3).Infof("ensure(%s): sg(%s) - updating", serviceName, *sg.Name) _, err := az.SecurityGroupsClient.CreateOrUpdate(az.ResourceGroup, *sg.Name, sg, nil) if err != nil { return nil, err } } lb, existsLb, err := az.getAzureLoadBalancer(lbName) if err != nil { return nil, err } if !existsLb { lb = network.LoadBalancer{ Name: &lbName, Location: &az.Location, Properties: &network.LoadBalancerPropertiesFormat{}, } } lb, lbNeedsUpdate, err := az.reconcileLoadBalancer(lb, pip, clusterName, service, nodeNames) if err != nil { return nil, err } if !existsLb || lbNeedsUpdate { glog.V(3).Infof("ensure(%s): lb(%s) - updating", serviceName, lbName) _, err = az.LoadBalancerClient.CreateOrUpdate(az.ResourceGroup, *lb.Name, lb, nil) if err != nil { return nil, err } } // Add the machines to the backend pool if they're not already lbBackendName := getBackendPoolName(clusterName) lbBackendPoolID := az.getBackendPoolID(lbName, lbBackendName) hostUpdates := make([]func() error, len(nodeNames)) for i, nodeName := range nodeNames { localNodeName := nodeName f := func() error { err := az.ensureHostInPool(serviceName, types.NodeName(localNodeName), lbBackendPoolID) if err != nil { return fmt.Errorf("ensure(%s): lb(%s) - failed to ensure host in pool: %q", serviceName, lbName, err) } return nil } hostUpdates[i] = f } errs := utilerrors.AggregateGoroutines(hostUpdates...) if errs != nil { return nil, utilerrors.Flatten(errs) } glog.V(2).Infof("ensure(%s): FINISH - %s", serviceName, *pip.Properties.IPAddress) return &v1.LoadBalancerStatus{ Ingress: []v1.LoadBalancerIngress{{IP: *pip.Properties.IPAddress}}, }, nil }