From 70a0f443c84918f4a12f726486bc559c45d3258f Mon Sep 17 00:00:00 2001 From: FengyunPan Date: Tue, 19 Sep 2017 09:43:24 +0800 Subject: [PATCH] Only register floatingIP for external loadbalancer service If the user has provided the floating-ip options, then it's safe to assume they want (only) the floating-ip to be the ingress IP; if they have not provided floating-ip options, then the LB IP is the only relevant value. Fix #52566 --- .../openstack/openstack_loadbalancer.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go b/pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go index a4cdca131cf..cb847835d72 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go +++ b/pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go @@ -869,10 +869,6 @@ func (lbaas *LbaasV2) EnsureLoadBalancer(clusterName string, apiService *v1.Serv glog.V(2).Infof("Deleted obsolete listener: %s", listener.ID) } - status := &v1.LoadBalancerStatus{} - - status.Ingress = []v1.LoadBalancerIngress{{IP: loadbalancer.VipAddress}} - portID := loadbalancer.VipPortID floatIP, err := getFloatingIPByPortID(lbaas.network, portID) if err != nil && err != ErrNotFound { @@ -895,8 +891,13 @@ func (lbaas *LbaasV2) EnsureLoadBalancer(clusterName string, apiService *v1.Serv return nil, fmt.Errorf("Error creating LB floatingip %+v: %v", floatIPOpts, err) } } + + status := &v1.LoadBalancerStatus{} + if floatIP != nil { - status.Ingress = append(status.Ingress, v1.LoadBalancerIngress{IP: floatIP.FloatingIP}) + status.Ingress = []v1.LoadBalancerIngress{{IP: floatIP.FloatingIP}} + } else { + status.Ingress = []v1.LoadBalancerIngress{{IP: loadbalancer.VipAddress}} } if lbaas.opts.ManageSecurityGroups { @@ -1453,9 +1454,6 @@ func (lb *LbaasV1) EnsureLoadBalancer(clusterName string, apiService *v1.Service } status := &v1.LoadBalancerStatus{} - - status.Ingress = []v1.LoadBalancerIngress{{IP: vip.Address}} - if floatingPool != "" && !internalAnnotation { floatIPOpts := floatingips.CreateOpts{ FloatingNetworkID: floatingPool, @@ -1472,7 +1470,9 @@ func (lb *LbaasV1) EnsureLoadBalancer(clusterName string, apiService *v1.Service return nil, fmt.Errorf("Error creating floatingip for openstack load balancer %s: %v", name, err) } - status.Ingress = append(status.Ingress, v1.LoadBalancerIngress{IP: floatIP.FloatingIP}) + status.Ingress = []v1.LoadBalancerIngress{{IP: floatIP.FloatingIP}} + } else { + status.Ingress = []v1.LoadBalancerIngress{{IP: vip.Address}} } return status, nil