Skip to content

Commit

Permalink
fix chassis gc (#3525)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian authored and bobz965 committed Dec 15, 2023
1 parent 949ec02 commit 8165d2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 11 additions & 1 deletion pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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
}

Expand Down
13 changes: 11 additions & 2 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8165d2c

Please sign in to comment.