Skip to content

Commit

Permalink
fix OVN LS/LB gc (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Nov 23, 2022
1 parent 8aa724e commit aef4cd3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package controller
import (
"context"
"fmt"
"strings"

corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"strings"

kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/kubeovn/kube-ovn/pkg/ovs"
Expand Down Expand Up @@ -125,7 +126,9 @@ func (c *Controller) gcLogicalSwitch() error {
return err
}
subnetNames := make([]string, 0, len(subnets))
subnetMap := make(map[string]*kubeovnv1.Subnet, len(subnets))
for _, s := range subnets {
subnetMap[s.Name] = s
subnetNames = append(subnetNames, s.Name)
}
lss, err := c.ovnLegacyClient.ListLogicalSwitch(c.config.EnableExternalVpc)
Expand All @@ -141,12 +144,14 @@ func (c *Controller) gcLogicalSwitch() error {
ls == c.config.ExternalGatewaySwitch {
continue
}
if !util.IsStringIn(ls, subnetNames) {
klog.Infof("gc subnet %s", ls)
if err := c.handleDeleteLogicalSwitch(ls); err != nil {
klog.Errorf("failed to gc subnet %s, %v", ls, err)
return err
}
if s := subnetMap[ls]; s != nil && isOvnSubnet(s) {
continue
}

klog.Infof("gc subnet %s", ls)
if err := c.handleDeleteLogicalSwitch(ls); err != nil {
klog.Errorf("failed to gc subnet %s, %v", ls, err)
return err
}
}

Expand Down Expand Up @@ -385,13 +390,17 @@ func (c *Controller) gcLoadBalancer() error {
for _, cachedVpc := range vpcs {
vpc := cachedVpc.DeepCopy()
for _, subnetName := range vpc.Status.Subnets {
_, err := c.subnetsLister.Get(subnetName)
subnet, err := c.subnetsLister.Get(subnetName)
if err != nil {
if k8serrors.IsNotFound(err) {
continue
}
return err
}
if !isOvnSubnet(subnet) {
continue
}

err = c.ovnLegacyClient.RemoveLbFromLogicalSwitch(
vpc.Status.TcpLoadBalancer,
vpc.Status.TcpSessionLoadBalancer,
Expand Down

0 comments on commit aef4cd3

Please sign in to comment.