From ad7f0266436fcbba97bda7ebef68ddc037720d7e Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Tue, 22 Nov 2022 15:24:51 +0800 Subject: [PATCH 1/2] fix OVN LB gc --- pkg/controller/gc.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/controller/gc.go b/pkg/controller/gc.go index aa75a517264..7b808da6910 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" @@ -385,13 +386,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, From 0b7383b31b2f9526e5600f42afdc681a1da3c328 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Tue, 22 Nov 2022 15:54:16 +0800 Subject: [PATCH 2/2] fix subnet gc --- pkg/controller/gc.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/controller/gc.go b/pkg/controller/gc.go index 7b808da6910..d85ff561aed 100644 --- a/pkg/controller/gc.go +++ b/pkg/controller/gc.go @@ -126,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) @@ -142,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 } }