diff --git a/pkg/controller/gc.go b/pkg/controller/gc.go index 06200c3118b..d5d569c24cd 100644 --- a/pkg/controller/gc.go +++ b/pkg/controller/gc.go @@ -715,7 +715,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) } @@ -737,6 +737,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 @@ -747,6 +748,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 }