Skip to content

Commit

Permalink
fix: load-balancer for dnat cleaned after restarting kube-ovn-controller
Browse files Browse the repository at this point in the history
Signed-off-by: zcq98 <[email protected]>
  • Loading branch information
zcq98 committed Aug 1, 2024
1 parent df2d066 commit 3fc8a17
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,19 @@ func (c *Controller) markAndCleanLSP() error {

func (c *Controller) gcLoadBalancer() error {
klog.Infof("start to gc load balancers")

var vpcLbs []string

dnats, err := c.ovnDnatRulesLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list dnats, %v", err)
return err
}

for _, dnat := range dnats {
vpcLbs = append(vpcLbs, dnat.Name)
}

if !c.config.EnableLb {
// remove lb from logical switch
vpcs, err := c.vpcsLister.List(labels.Everything())
Expand Down Expand Up @@ -467,7 +480,9 @@ func (c *Controller) gcLoadBalancer() error {
}
}
// lbs will remove from logical switch automatically when delete lbs
if err = c.OVNNbClient.DeleteLoadBalancers(nil); err != nil {
if err = c.OVNNbClient.DeleteLoadBalancers(func(lb *ovnnb.LoadBalancer) bool {
return !slices.Contains(vpcLbs, lb.Name)
}); err != nil {
klog.Errorf("delete all load balancers: %v", err)
return err
}
Expand All @@ -480,12 +495,6 @@ func (c *Controller) gcLoadBalancer() error {
return err
}

dnats, err := c.ovnDnatRulesLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list dnats, %v", err)
return err
}

var (
tcpVips = strset.NewWithSize(len(svcs) * 2)
udpVips = strset.NewWithSize(len(svcs) * 2)
Expand Down Expand Up @@ -531,14 +540,9 @@ func (c *Controller) gcLoadBalancer() error {

var (
removeVip func(lbName string, svcVips *strset.Set) error
vpcLbs []string
ignoreHealthCheck = true
)

for _, dnat := range dnats {
vpcLbs = append(vpcLbs, dnat.Name)
}

removeVip = func(lbName string, svcVips *strset.Set) error {
if lbName == "" {
return nil
Expand Down

0 comments on commit 3fc8a17

Please sign in to comment.