Skip to content

Commit

Permalink
fix: wrong deletion in gc lb and portgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Dec 22, 2019
1 parent e5f5541 commit 518c0a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
9 changes: 4 additions & 5 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ func (c *Controller) Run(stopCh <-chan struct{}) error {

go wait.Until(c.runAddIpPoolPodWorker, time.Second, stopCh)
go wait.Until(c.runAddNamespaceWorker, time.Second, stopCh)
go wait.Until(c.runDeleteTcpServiceWorker, time.Second, stopCh)
go wait.Until(c.runDeleteUdpServiceWorker, time.Second, stopCh)
for i := 0; i < c.config.WorkerNum; i++ {
go wait.Until(c.runAddPodWorker, time.Second, stopCh)
go wait.Until(c.runDeletePodWorker, time.Second, stopCh)
Expand All @@ -340,9 +342,6 @@ func (c *Controller) Run(stopCh <-chan struct{}) error {
go wait.Until(c.runDeleteNodeWorker, time.Second, stopCh)

go wait.Until(c.runUpdateServiceWorker, time.Second, stopCh)
go wait.Until(c.runDeleteTcpServiceWorker, time.Second, stopCh)
go wait.Until(c.runDeleteUdpServiceWorker, time.Second, stopCh)

go wait.Until(c.runUpdateEndpointWorker, time.Second, stopCh)

go wait.Until(c.runUpdateNpWorker, time.Second, stopCh)
Expand Down Expand Up @@ -497,7 +496,7 @@ func (c *Controller) gcLoadBalancer() error {
klog.Errorf("failed to get udp lb vips %v", err)
return err
}
for _, vip := range vips {
for vip := range vips {
if !util.IsStringIn(vip, tcpVips) {
err := c.ovnClient.DeleteLoadBalancerVip(vip, c.config.ClusterTcpLoadBalancer)
if err != nil {
Expand All @@ -517,7 +516,7 @@ func (c *Controller) gcLoadBalancer() error {
klog.Errorf("failed to get udp lb vips %v", err)
return err
}
for _, vip := range vips {
for vip := range vips {
if !util.IsStringIn(vip, udpVips) {
err := c.ovnClient.DeleteLoadBalancerVip(vip, c.config.ClusterUdpLoadBalancer)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
if port.Protocol == v1.ProtocolTCP {
// for performance reason delete lb with no backends
if len(backends) > 0 {
err = c.ovnClient.CreateLoadBalancerRule(c.config.ClusterTcpLoadBalancer, vip, getServicePortBackends(ep, port, clusterIP))
err = c.ovnClient.CreateLoadBalancerRule(c.config.ClusterTcpLoadBalancer, vip, getServicePortBackends(ep, port, clusterIP), string(port.Protocol))
if err != nil {
klog.Errorf("failed to update vip %s to tcp lb, %v", vip, err)
return err
Expand All @@ -135,7 +135,7 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
}
} else {
if len(backends) > 0 {
err = c.ovnClient.CreateLoadBalancerRule(c.config.ClusterUdpLoadBalancer, vip, getServicePortBackends(ep, port, clusterIP))
err = c.ovnClient.CreateLoadBalancerRule(c.config.ClusterUdpLoadBalancer, vip, getServicePortBackends(ep, port, clusterIP), string(port.Protocol))
if err != nil {
klog.Errorf("failed to update vip %s to udp lb, %v", vip, err)
return err
Expand Down
13 changes: 9 additions & 4 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ func (c Client) CreateLoadBalancer(lb, protocol string) error {
}

// CreateLoadBalancerRule create loadbalancer rul in ovn
func (c Client) CreateLoadBalancerRule(lb, vip, ips string) error {
_, err := c.ovnNbCommand(MayExist, "lb-add", lb, vip, ips)
func (c Client) CreateLoadBalancerRule(lb, vip, ips, protocol string) error {
_, err := c.ovnNbCommand(MayExist, "lb-add", lb, vip, ips, strings.ToLower(protocol))
return err
}

Expand All @@ -315,7 +315,12 @@ func (c Client) addLoadBalancerToLogicalSwitch(lb, ls string) error {

// DeleteLoadBalancerVip delete a vip rule from loadbalancer
func (c Client) DeleteLoadBalancerVip(vip, lb string) error {
_, err := c.ovnNbCommand(IfExists, "lb-del", lb, vip)
existVips, err := c.GetLoadBalancerVips(lb)
// vip is empty or delete last rule will destroy the loadbalancer
if vip == "" || len(existVips) == 1 || existVips[vip] == "" {
return nil
}
_, err = c.ovnNbCommand(IfExists, "lb-del", lb, vip)
return err
}

Expand Down Expand Up @@ -496,7 +501,7 @@ func (c Client) ListPortGroup() ([]portGroup, error) {
continue
}
name := strings.TrimSpace(parts[0])
np := strings.Split(strings.TrimSpace(parts[1]), "/")
np := strings.Split(strings.TrimPrefix(strings.TrimSpace(parts[1]), "np="), "/")
if len(np) != 2 {
continue
}
Expand Down

0 comments on commit 518c0a7

Please sign in to comment.