Skip to content

Commit

Permalink
fix chassis update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobz965 committed Aug 8, 2023
1 parent dc7c7e9 commit 2d5e395
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 144 deletions.
98 changes: 68 additions & 30 deletions mocks/pkg/ovs/interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/controller/external-gw.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func (c *Controller) getGatewayChassis(config map[string]string) ([]string, erro
klog.Error(err)
return chassises, err
}
klog.Infof("get node %s chassis: %s", gw, annoChassisName)
chassis, err := c.ovnSbClient.GetChassis(annoChassisName, false)
if err != nil {
klog.Errorf("failed to get node %s chassis: %s, %v", node.Name, annoChassisName, err)
Expand Down
53 changes: 20 additions & 33 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controller
import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"strconv"
Expand Down Expand Up @@ -861,26 +860,26 @@ func (c *Controller) checkGatewayReady() error {
}

func (c *Controller) checkChassisDupl(node *v1.Node) error {
// TODO:// check multi chassis has the same node name
// notice that multiple chassises may arise and we are not prepared
annoChassisName := node.Annotations[util.ChassisAnnotation]
if annoChassisName == "" {
err := fmt.Errorf("node %s has no chassis annotation, kube-ovn-cni not ready", node.Name)
klog.Error(err)
return err
}
chassis, err := c.ovnSbClient.GetChassis(annoChassisName, false)
// check multi chassis has the same node name
css, err := c.ovnSbClient.ListChassis()
if err != nil {
klog.Errorf("failed to get node %s chassis: %s, %v", node.Name, annoChassisName, err)
klog.Errorf("failed to list chassis %v", err)
return err
}
if chassis.Hostname == node.Name {
return nil
}
klog.Warningf("delete duplicate chassis for node %s and new chassis %s", node.Name, chassis.Name)
if err := c.ovnSbClient.DeleteChassisByNode(node.Name); err != nil {
klog.Errorf("failed to delete chassis for node %s %v", node.Name, err)
return err
var nodeChassisMap = make(map[string]string, len(*css))
for _, cs := range *css {
if nodeChassisMap[cs.Hostname] == "" {
nodeChassisMap[cs.Hostname] = cs.Name
} else {
klog.Warningf("node %s has multiple chassis %s and %s", cs.Hostname, nodeChassisMap[cs.Hostname], cs.Name)
if err := c.ovnSbClient.DeleteChassis(cs.Name); err != nil {
klog.Warningf("node %s chassis duplicated, delete all its chassises", node.Name)
if err := c.ovnSbClient.DeleteChassisByNode(node.Name); err != nil {
klog.Errorf("failed to delete chassis for node %s %v", node.Name, err)
return err
}
}
}
}
return nil
}
Expand Down Expand Up @@ -1004,32 +1003,20 @@ func (c *Controller) validateChassis(node *v1.Node) error {
// kube-ovn-cni not ready to set chassis
return nil
}
klog.Infof("validate chassis for node %s, chassis %s", node.Name, annoChassisName)
chassis, err := c.ovnSbClient.GetChassis(annoChassisName, false)
if err != nil {
klog.Errorf("failed to get node %s chassis: %s, %v", node.Name, annoChassisName, err)
return err
}
if annoChassisName == chassis.Name && chassis.ExternalIDs != nil && chassis.ExternalIDs[util.ExternalIDsNodeKey] != node.Name {
if chassis.ExternalIDs == nil || chassis.ExternalIDs[util.ExternalIDsNodeKey] != node.Name {
klog.Infof("init tag for node %s, chassis %s, host name %s", node.Name, annoChassisName, node.Name)
if err = c.ovnSbClient.InitChassisNodeTag(chassis.Name, node.Name); err != nil {
return fmt.Errorf("failed to init chassis tag, %v", err)
}
return nil
}
if chassis.Name == "" {
// If no chassisID for this node is obtained, we need to perform GC in order for the chassis to be re-registered
if err = c.gcChassis(); err != nil {
return fmt.Errorf("failed to gc chassis, %v", err)
}
} else {
// When the ids are obtained but are inconsistent, it is usually because there are duplicate chassis records.
// All chassis related to Node need to be deleted so that the correct chassis can be registered again
if err := c.ovnSbClient.DeleteChassisByNode(node.Name); err != nil {
klog.Errorf("failed to delete chassis for node %s %v", node.Name, err)
return err
}
}
return errors.New("chassis reset, reboot ovs-ovn on this node: " + node.Name)
return nil
}

func (c *Controller) addNodeGwStaticRoute() error {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/ovn-ic.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (c *Controller) establishInterConnection(config map[string]string) error {
klog.Error(err)
return err
}
klog.Infof("gw node %s chassis %s", gw, annoChassisName)
chassis, err := c.ovnSbClient.GetChassis(annoChassisName, false)
if err != nil {
klog.Errorf("failed to get node chassis %s, %v", annoChassisName, err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/ovs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ type OvnClient interface {
}

type Chassis interface {
CreateChassis(chassisName, nodeName string) (*ovnsb.Chassis, error)
UpdateChassis(chassis *ovnsb.Chassis, fields ...interface{}) error
DeleteChassis(chassisName string) error
DeleteChassisByNode(node string) error
GetChassisByHost(nodeName string) (*ovnsb.Chassis, error)
GetChassis(chassisName string, ignoreNotFound bool) (*ovnsb.Chassis, error)
GetChassisByTagNode(nodeName string) (*ovnsb.Chassis, error)
GetKubeOvnChassisses() (*[]ovnsb.Chassis, error)
InitChassisNodeTag(chassisName string, nodeName string) error
ListChassis() (*[]ovnsb.Chassis, error)
}
Loading

0 comments on commit 2d5e395

Please sign in to comment.