Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 committed Nov 23, 2023
1 parent 73d4be3 commit d7eff7e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 58 deletions.
2 changes: 2 additions & 0 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ VLAN_ID="100"

if [ "$ENABLE_VLAN" = "true" ]; then
NETWORK_TYPE="vlan"
# ENABLE_EIP_SNAT is only supported when you use vpc, vlan not support
ENABLE_EIP_SNAT=${ENABLE_EIP_SNAT:-false}
if [ "$VLAN_NIC" != "" ]; then
VLAN_INTERFACE_NAME="$VLAN_NIC"
fi
Expand Down
32 changes: 16 additions & 16 deletions mocks/pkg/ovs/interface.go

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

13 changes: 9 additions & 4 deletions pkg/controller/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {

var externalSubnet *kubeovnv1.Subnet
externalSubnetExist := false
if c.config.EnableEipSnat && c.config.NetworkType != util.NetworkTypeVlan {
if c.config.EnableEipSnat {
externalSubnet, err = c.subnetsLister.Get(c.config.ExternalGatewaySwitch)
if err != nil {
klog.Errorf("failed to get external subnet %s: %v", c.config.ExternalGatewaySwitch, err)
} else {
isExternalSubnetExist = true
externalSubnetExist = true
}
}

Expand Down Expand Up @@ -374,7 +374,7 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
if err == nil {
nextHop := cm.Data["external-gw-addr"]
if nextHop == "" {
if !isExternalSubnetExist {
if !externalSubnetExist {
err = fmt.Errorf("no available external subnet")
klog.Error(err)
return err
Expand Down Expand Up @@ -549,8 +549,13 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
}
}

if isExternalSubnetExist && vpc.Name != util.DefaultVpc && !externalSubnet.Spec.LogicalGateway {
if vpc.Name != util.DefaultVpc && !externalSubnet.Spec.LogicalGateway {
if cachedVpc.Spec.EnableExternal {
if !externalSubnetExist {
err = fmt.Errorf("no available external subnet")
klog.Error(err)
return err
}
if !cachedVpc.Status.EnableExternal {
// connect vpc to default external
klog.Infof("connect external network with vpc %s", vpc.Name)
Expand Down
8 changes: 4 additions & 4 deletions pkg/ovs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type LogicalRouterPort interface {
GetLogicalRouterPort(lrpName string, ignoreNotFound bool) (*ovnnb.LogicalRouterPort, error)
GetLogicalRouterPortByUUID(uuid string) (*ovnnb.LogicalRouterPort, error)
ListLogicalRouterPorts(externalIDs map[string]string, filter func(lrp *ovnnb.LogicalRouterPort) bool) ([]ovnnb.LogicalRouterPort, error)
ListGatewayChassisByLogicalRouterPort(lrpName string, ignoreNotFound bool) (*[]ovnnb.GatewayChassis, error)
ListGatewayChassisByLogicalRouterPort(lrpName string, ignoreNotFound bool) ([]ovnnb.GatewayChassis, error)
LogicalRouterPortExists(lrpName string) (bool, error)
}

Expand All @@ -50,9 +50,9 @@ type GatewayChassis interface {
type BFD interface {
CreateBFD(lrpName, dstIP string, minRx, minTx, detectMult int) (*ovnnb.BFD, error)
DeleteBFD(lrpName, dstIP string) error
ListBFD(lrpName, dstIP string) (*[]ovnnb.BFD, error)
ListDownBFDs(dstIP string) (*[]ovnnb.BFD, error)
ListUpBFDs(dstIP string) (*[]ovnnb.BFD, error)
ListBFD(lrpName, dstIP string) ([]ovnnb.BFD, error)
ListDownBFDs(dstIP string) ([]ovnnb.BFD, error)
ListUpBFDs(dstIP string) ([]ovnnb.BFD, error)
UpdateBFD(bfd *ovnnb.BFD, fields ...interface{}) error
MonitorBFD()
}
Expand Down
42 changes: 21 additions & 21 deletions pkg/ovs/ovn-nb-bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ovn-org/libovsdb/model"
)

func (c *OVNNbClient) ListBFD(lrpName, dstIP string) (*[]ovnnb.BFD, error) {
func (c *OVNNbClient) ListBFD(lrpName, dstIP string) ([]ovnnb.BFD, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
defer cancel()

Expand All @@ -30,10 +30,10 @@ func (c *OVNNbClient) ListBFD(lrpName, dstIP string) (*[]ovnnb.BFD, error) {
return nil, err
}

return &bfdList, nil
return bfdList, nil
}

func (c *OVNNbClient) ListDownBFDs(dstIP string) (*[]ovnnb.BFD, error) {
func (c *OVNNbClient) ListDownBFDs(dstIP string) ([]ovnnb.BFD, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
defer cancel()

Expand All @@ -49,10 +49,10 @@ func (c *OVNNbClient) ListDownBFDs(dstIP string) (*[]ovnnb.BFD, error) {
return nil, err
}

return &bfdList, nil
return bfdList, nil
}

func (c *OVNNbClient) ListUpBFDs(dstIP string) (*[]ovnnb.BFD, error) {
func (c *OVNNbClient) ListUpBFDs(dstIP string) ([]ovnnb.BFD, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
defer cancel()

Expand All @@ -65,7 +65,7 @@ func (c *OVNNbClient) ListUpBFDs(dstIP string) (*[]ovnnb.BFD, error) {
return nil, err
}

return &bfdList, nil
return bfdList, nil
}

func (c *OVNNbClient) CreateBFD(lrpName, dstIP string, minRx, minTx, detectMult int) (*ovnnb.BFD, error) {
Expand All @@ -74,8 +74,8 @@ func (c *OVNNbClient) CreateBFD(lrpName, dstIP string, minRx, minTx, detectMult
klog.Error(err)
return nil, err
}
if len(*bfdList) != 0 {
return &(*bfdList)[0], nil
if len(bfdList) != 0 {
return &bfdList[0], nil
}

bfd := &ovnnb.BFD{
Expand All @@ -100,10 +100,10 @@ func (c *OVNNbClient) CreateBFD(lrpName, dstIP string, minRx, minTx, detectMult
if bfdList, err = c.ListBFD(lrpName, dstIP); err != nil {
return nil, err
}
if len(*bfdList) == 0 {
if len(bfdList) == 0 {
return nil, fmt.Errorf("BFD with logical_port=%s and dst_ip=%s not found", lrpName, dstIP)
}
return &(*bfdList)[0], nil
return &bfdList[0], nil
}

// UpdateBFD update BFD
Expand All @@ -128,12 +128,12 @@ func (c *OVNNbClient) DeleteBFD(lrpName, dstIP string) error {
klog.Error(err)
return err
}
if len(*bfdList) == 0 {
if len(bfdList) == 0 {
return nil
}

for _, bfd := range *bfdList {
ops, err := c.Where(&bfd).Delete()
for _, bfd := range bfdList {
ops, err := c.Where(bfd).Delete()
if err != nil {
err := fmt.Errorf("failed to generate operations for BFD deletion with UUID %s: %v", bfd.UUID, err)
klog.Error(err)
Expand Down Expand Up @@ -172,12 +172,12 @@ func (c *OVNNbClient) isLrpBfdUp(lrpName, dstIP string) (bool, error) {
klog.Errorf("failed to list bfd for lrp %s, %v", lrpName, err)
return false, err
}
if len(*bfdList) == 0 {
if len(bfdList) == 0 {
klog.Errorf("no bfd for lrp %s", lrpName)
// no bfd, means no need to handle
return true, nil
}
bfd := &(*bfdList)[0]
bfd := bfdList[0]
if bfd.Status == nil {
err := fmt.Errorf("lrp %s bfd status is nil", lrpName)
klog.Error(err)
Expand Down Expand Up @@ -260,11 +260,11 @@ func (c *OVNNbClient) bfdUpdateL3HAHandler(table string, oldModel, newModel mode
klog.Errorf("failed to list gateway chassis for lrp %s, %v", lrpName, err)
return
}
if len(*gwChassisList) == 0 {
if len(gwChassisList) == 0 {
klog.Errorf("no gateway chassis for lrp %s", lrpName)
return
}
goodChassis := (*gwChassisList)[0]
goodChassis := gwChassisList[0]
goodChassis.Priority = util.GwChassisMaxPriority + 1
klog.Infof("raise good chassis %s priority to %d", goodChassis.Name, goodChassis.Priority)
if err := c.UpdateGatewayChassis(&goodChassis, &goodChassis.Priority); err != nil {
Expand All @@ -283,11 +283,11 @@ func (c *OVNNbClient) bfdUpdateL3HAHandler(table string, oldModel, newModel mode
klog.Errorf("failed to list gateway chassis for lrp %s, %v", lrpName, err)
return
}
if len(*gwChassisList) == 0 {
if len(gwChassisList) == 0 {
klog.Errorf("no gateway chassis for lrp %s", lrpName)
return
}
badChassis := (*gwChassisList)[0]
badChassis := gwChassisList[0]
// centralized gw chassis node number probably less than 5
badChassis.Priority = util.GwChassisMaxPriority - 5
klog.Infof("lower bad chassis %s priority to %d", badChassis.Name, badChassis.Priority)
Expand All @@ -310,11 +310,11 @@ func (c *OVNNbClient) bfdUpdateL3HAHandler(table string, oldModel, newModel mode
klog.Errorf("failed to list gateway chassis for lrp %s, %v", lrpName, err)
return
}
if len(*gwChassisList) == 0 {
if len(gwChassisList) == 0 {
klog.Errorf("no gateway chassis for lrp %s", lrpName)
return
}
badChassis = (*gwChassisList)[0]
badChassis = gwChassisList[0]
if newBfd.ExternalIDs == nil {
newBfd.ExternalIDs = make(map[string]string)
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/ovs/ovn-nb-bfd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ func (suite *OvnClientTestSuite) testListBFD() {

bfdList, err := ovnClient.ListBFD(lrpName, dstIP1)
require.NoError(t, err)
require.Len(t, *bfdList, 1)
require.Equal(t, bfd1.UUID, (*bfdList)[0].UUID)
require.Len(t, bfdList, 1)
require.Equal(t, bfd1.UUID, bfdList[0].UUID)

bfdList, err = ovnClient.ListBFD(lrpName, dstIP2)
require.NoError(t, err)
require.Len(t, *bfdList, 1)
require.Equal(t, bfd2.UUID, (*bfdList)[0].UUID)
require.Len(t, bfdList, 1)
require.Equal(t, bfd2.UUID, bfdList[0].UUID)

bfdList, err = ovnClient.ListBFD(lrpName, "")
require.NoError(t, err)
require.Len(t, *bfdList, 2)
uuids := strset.NewWithSize(len(*bfdList))
for _, bfd := range *bfdList {
require.Len(t, bfdList, 2)
uuids := strset.NewWithSize(len(bfdList))
for _, bfd := range bfdList {
uuids.Add(bfd.UUID)
}
require.True(t, uuids.IsEqual(strset.New(bfd1.UUID, bfd2.UUID)))
Expand Down Expand Up @@ -99,12 +99,12 @@ func (suite *OvnClientTestSuite) testDeleteBFD() {

bfdList, err := ovnClient.ListBFD(lrpName, dstIP1)
require.NoError(t, err)
require.Len(t, *bfdList, 0)
require.Len(t, bfdList, 0)

bfdList, err = ovnClient.ListBFD(lrpName, dstIP2)
require.NoError(t, err)
require.Len(t, *bfdList, 1)
require.Equal(t, bfd2.UUID, (*bfdList)[0].UUID)
require.Len(t, bfdList, 1)
require.Equal(t, bfd2.UUID, bfdList[0].UUID)
})

t.Run("delete multiple BFDs", func(t *testing.T) {
Expand All @@ -113,6 +113,6 @@ func (suite *OvnClientTestSuite) testDeleteBFD() {

bfdList, err := ovnClient.ListBFD(lrpName, "")
require.NoError(t, err)
require.Len(t, *bfdList, 0)
require.Len(t, bfdList, 0)
})
}
4 changes: 2 additions & 2 deletions pkg/ovs/ovn-nb-gateway_chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *OVNNbClient) DeleteGatewayChassises(lrpName string, chassises []string)
}

// ListGatewayChassisByLogicalRouterPort get gateway chassis by lrp name
func (c *OVNNbClient) ListGatewayChassisByLogicalRouterPort(lrpName string, ignoreNotFound bool) (*[]ovnnb.GatewayChassis, error) {
func (c *OVNNbClient) ListGatewayChassisByLogicalRouterPort(lrpName string, ignoreNotFound bool) ([]ovnnb.GatewayChassis, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
defer cancel()

Expand All @@ -95,7 +95,7 @@ func (c *OVNNbClient) ListGatewayChassisByLogicalRouterPort(lrpName string, igno
return nil, err
}

return &gwChassisList, nil
return gwChassisList, nil
}

// GetGatewayChassis get gateway chassis by name
Expand Down

0 comments on commit d7eff7e

Please sign in to comment.