From 690449809d021d06570e198a0cd9e31984c7c668 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Thu, 14 Dec 2023 09:54:55 +0000 Subject: [PATCH] fix chassis gc Signed-off-by: zhangzujian --- pkg/controller/gc.go | 12 +++++++++++- pkg/controller/node.go | 13 +++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pkg/controller/gc.go b/pkg/controller/gc.go index 01c352a81ab..bc7018a580b 100644 --- a/pkg/controller/gc.go +++ b/pkg/controller/gc.go @@ -707,7 +707,7 @@ func (c *Controller) gcStaticRoute() error { func (c *Controller) gcChassis() error { klog.Infof("start to gc chassis") - chassises, err := c.OVNSbClient.GetKubeOvnChassisses() + chassises, err := c.OVNSbClient.ListChassis() if err != nil { klog.Errorf("failed to get all chassis, %v", err) } @@ -729,6 +729,7 @@ func (c *Controller) gcChassis() error { if hostname, exist := chassisNodes[chassisName]; exist { if hostname == node.Name { // node is alive, matched chassis should be alive + delete(chassisNodes, chassisName) continue } // maybe node name changed, delete chassis @@ -739,6 +740,15 @@ func (c *Controller) gcChassis() error { } } } + + for chassisName, hostname := range chassisNodes { + klog.Infof("gc node %s chassis %s", hostname, chassisName) + if err := c.OVNSbClient.DeleteChassis(chassisName); err != nil { + klog.Errorf("failed to delete node %s chassis %s %v", hostname, chassisName, err) + return err + } + } + return nil } diff --git a/pkg/controller/node.go b/pkg/controller/node.go index e171c984c60..c8880fc1985 100644 --- a/pkg/controller/node.go +++ b/pkg/controller/node.go @@ -992,17 +992,26 @@ func (c *Controller) UpdateChassisTag(node *v1.Node) error { // kube-ovn-cni not ready to set chassis return nil } - chassis, err := c.OVNSbClient.GetChassis(annoChassisName, false) + chassis, err := c.OVNSbClient.GetChassis(annoChassisName, true) if err != nil { klog.Errorf("failed to get node %s chassis: %s, %v", node.Name, annoChassisName, err) return err } + if chassis == nil { + klog.Infof("chassis not registered for node %s, do chassis gc once", node.Name) + // chassis name conflict, do GC + if err = c.gcChassis(); err != nil { + klog.Errorf("failed to gc chassis: %v", err) + return err + } + return fmt.Errorf("chassis not registered for node %s, will try again later", node.Name) + } + if chassis.ExternalIDs == nil || chassis.ExternalIDs["vendor"] != util.CniTypeName { klog.Infof("init tag %s for node %s chassis", util.CniTypeName, node.Name) if err = c.OVNSbClient.UpdateChassisTag(chassis.Name, node.Name); err != nil { return fmt.Errorf("failed to init chassis tag, %v", err) } - return nil } return nil }