mirror of https://github.com/k3s-io/k3s
Code review correction
Inverting code path on CreateTcploadBalancer to avoid branch divergence Removing useless variable vipAddr as vip have information needed Renaming 'error' variable on EnsureTCPLoadBalancerDeleted to be consistentpull/6/head
parent
be5f9094d0
commit
4c57053d2c
|
@ -677,26 +677,20 @@ func (lb *LoadBalancer) CreateTCPLoadBalancer(name, region string, externalIP ne
|
||||||
|
|
||||||
status := &api.LoadBalancerStatus{}
|
status := &api.LoadBalancerStatus{}
|
||||||
|
|
||||||
if lb.opts.FloatingNetworkId == "" {
|
status.Ingress = []api.LoadBalancerIngress{{IP: vip.Address}}
|
||||||
status.Ingress = []api.LoadBalancerIngress{{IP: vip.Address}}
|
|
||||||
|
|
||||||
return status, nil
|
if lb.opts.FloatingNetworkId != "" {
|
||||||
}
|
floatIPOpts := floatingips.CreateOpts{
|
||||||
|
FloatingNetworkID: lb.opts.FloatingNetworkId,
|
||||||
|
PortID: vip.PortID,
|
||||||
|
}
|
||||||
|
floatIP, err := floatingips.Create(lb.network, floatIPOpts).Extract()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
vipAddr, err := getVipByName(lb.network, name)
|
status.Ingress = append(status.Ingress, api.LoadBalancerIngress{IP: floatIP.FloatingIP})
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
floatIPOpts := floatingips.CreateOpts{
|
|
||||||
FloatingNetworkID: lb.opts.FloatingNetworkId,
|
|
||||||
PortID: vipAddr.PortID,
|
|
||||||
}
|
|
||||||
floatIP, err := floatingips.Create(lb.network, floatIPOpts).Extract()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
status.Ingress = []api.LoadBalancerIngress{{IP: vip.Address}, {IP: floatIP.FloatingIP}}
|
|
||||||
|
|
||||||
return status, nil
|
return status, nil
|
||||||
|
|
||||||
|
@ -777,9 +771,9 @@ func (lb *LoadBalancer) EnsureTCPLoadBalancerDeleted(name, region string) error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if floatingIP != nil {
|
if floatingIP != nil {
|
||||||
error := floatingips.Delete(lb.network, floatingIP.ID).ExtractErr()
|
err = floatingips.Delete(lb.network, floatingIP.ID).ExtractErr()
|
||||||
if error != nil && !isNotFound(error) {
|
if err != nil && !isNotFound(err) {
|
||||||
return error
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue