From aef4cd3a6324bfe4a65c02deb1d4331ab3aba9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A5=96=E5=BB=BA?= Date: Wed, 23 Nov 2022 09:38:25 +0800 Subject: [PATCH] fix OVN LS/LB gc (#2069) --- pkg/controller/gc.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/controller/gc.go b/pkg/controller/gc.go index aa75a517264..d85ff561aed 100644 --- a/pkg/controller/gc.go +++ b/pkg/controller/gc.go @@ -3,6 +3,8 @@ 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" @@ -10,7 +12,6 @@ import ( "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" @@ -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) @@ -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 } } @@ -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,