Skip to content

Commit

Permalink
bump libovsdb (#3731)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian authored and zbb88888 committed Mar 8, 2024
1 parent b9092b9 commit 3bfaf62
Show file tree
Hide file tree
Showing 21 changed files with 603 additions and 563 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/evanphx/json-patch/v5 v5.9.0
github.com/go-logr/stdr v1.2.2
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/greenpau/ovsdb v1.0.3
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.6.0
github.com/k8snetworkplumbingwg/sriovnet v1.2.0
Expand All @@ -36,6 +37,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/vishvananda/netlink v1.2.1-beta.2
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
go.uber.org/mock v0.4.0
golang.org/x/mod v0.15.0
golang.org/x/sys v0.17.0
golang.org/x/time v0.5.0
Expand Down Expand Up @@ -228,6 +230,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
Expand Down
21 changes: 18 additions & 3 deletions pkg/ovs/ovn-nb-acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,13 @@ func (suite *OvnClientTestSuite) testGetACL() {
priority := "2000"
match := "ip4.dst == 100.64.0.0/16"

err := ovnClient.CreateBareACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated)
err := ovnClient.CreatePortGroup(pgName, nil)
require.NoError(t, err)

acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated)
require.NoError(t, err)

err = ovnClient.CreateAcls(pgName, portGroupKey, acl)
require.NoError(t, err)

t.Run("direction, priority and match are same", func(t *testing.T) {
Expand Down Expand Up @@ -1469,18 +1475,27 @@ func (suite *OvnClientTestSuite) testListAcls() {
pgName := "test-list-acl-pg"
basePort := 50000

err := ovnClient.CreatePortGroup(pgName, nil)
require.NoError(t, err)

matchPrefix := "outport == @ovn.sg.test_list_acl_pg && ip"
// create two to-lport acl
for i := 0; i < 2; i++ {
match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i)
err := ovnClient.CreateBareACL(pgName, ovnnb.ACLDirectionToLport, "9999", match, ovnnb.ACLActionAllowRelated)
acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, "9999", match, ovnnb.ACLActionAllowRelated)
require.NoError(t, err)

err = ovnClient.CreateAcls(pgName, portGroupKey, acl)
require.NoError(t, err)
}

// create two from-lport acl
for i := 0; i < 3; i++ {
match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i)
err := ovnClient.CreateBareACL(pgName, ovnnb.ACLDirectionFromLport, "9999", match, ovnnb.ACLActionAllowRelated)
acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionFromLport, "9999", match, ovnnb.ACLActionAllowRelated)
require.NoError(t, err)

err = ovnClient.CreateAcls(pgName, portGroupKey, acl)
require.NoError(t, err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ovs/ovn-nb-bfd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (suite *OvnClientTestSuite) testDeleteBFD() {
t.Parallel()

ovnClient := suite.ovnClient
lrpName := "test-list-bfd"
lrpName := "test-del-bfd"
dstIP1 := "192.168.124.4"
dstIP2 := "192.168.124.5"
minRx1, minTx1, detectMult1 := 101, 102, 19
Expand Down
36 changes: 23 additions & 13 deletions pkg/ovs/ovn-nb-gateway_chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,33 @@ func (c *OVNNbClient) DeleteGatewayChassises(lrpName string, chassises []string)
return nil
}

ops := make([]ovsdb.Operation, 0, len(chassises))
lrp, err := c.GetLogicalRouterPort(lrpName, false)
if err != nil {
klog.Error(err)
return err
}

ops := make([]ovsdb.Operation, 0, len(chassises)*2)
for _, chassisName := range chassises {
gwChassisName := lrpName + "-" + chassisName
op, err := c.DeleteGatewayChassisOp(gwChassisName)
uuid, delOps, err := c.DeleteGatewayChassisOp(gwChassisName)
if err != nil {
klog.Error(err)
return nil
}

// ignore non-existent object
if len(op) == 0 {
continue
mutateOps, err := c.Where(lrp).Mutate(lrp, model.Mutation{
Field: &lrp.GatewayChassis,
Value: []string{uuid},
Mutator: ovsdb.MutateOperationDelete,
})
if err != nil {
klog.Error(err)
return nil
}

ops = append(ops, op...)
ops = append(ops, mutateOps...)
ops = append(ops, delOps...)
}

if err := c.Transact("gateway-chassises-delete", ops); err != nil {
Expand Down Expand Up @@ -203,23 +214,22 @@ func (c *OVNNbClient) CreateGatewayChassisesOp(lrpName string, chassises []strin
}

// DeleteGatewayChassisOp create operation which delete gateway chassis
func (c *OVNNbClient) DeleteGatewayChassisOp(chassisName string) ([]ovsdb.Operation, error) {
func (c *OVNNbClient) DeleteGatewayChassisOp(chassisName string) (uuid string, ops []ovsdb.Operation, err error) {
gwChassis, err := c.GetGatewayChassis(chassisName, true)
if err != nil {
klog.Error(err)
return nil, err
return "", nil, err
}

// not found, skip
if gwChassis == nil {
return nil, nil
return "", nil, nil
}

op, err := c.Where(gwChassis).Delete()
if err != nil {
if ops, err = c.Where(gwChassis).Delete(); err != nil {
klog.Error(err)
return nil, err
return "", nil, err
}

return op, nil
return gwChassis.UUID, ops, nil
}
60 changes: 28 additions & 32 deletions pkg/ovs/ovn-nb-gateway_chassis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,37 @@ import (
"github.com/ovn-org/libovsdb/ovsdb"
"github.com/stretchr/testify/require"

ovsclient "github.com/kubeovn/kube-ovn/pkg/ovsdb/client"
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
"github.com/kubeovn/kube-ovn/pkg/util"
)

func (suite *OvnClientTestSuite) testCreateGatewayChassises() {
t := suite.T()
t.Parallel()

ovnClient := suite.ovnClient
lrName := "test-create-gateway-chassises-lr"
lrpName := "test-create-gateway-chassises-lrp"
chassises := []string{"c7efec70-9519-4b03-8b67-057f2a95e5c7", "4a0891b6-fe81-4986-a367-aad0ea7ca9f3", "dcc2eda3-b3ea-4d53-afe0-7b6eaf7917ba"}

lrp := &ovnnb.LogicalRouterPort{
UUID: ovsclient.NamedUUID(),
Name: "test-create-gateway-chassises",
ExternalIDs: map[string]string{
"vendor": util.CniTypeName,
},
}
err := ovnClient.CreateLogicalRouter(lrName)
require.NoError(t, err)

err := createLogicalRouterPort(ovnClient, lrp)
err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"})
require.NoError(t, err)

err = ovnClient.CreateGatewayChassises(lrp.Name, chassises...)
err = ovnClient.CreateGatewayChassises(lrpName, chassises...)
require.NoError(t, err)

lrp, err = ovnClient.GetLogicalRouterPort(lrp.Name, false)
lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false)
require.NoError(t, err)
require.NotNil(t, lrp)
require.Len(t, lrp.GatewayChassis, len(chassises))

for i, chassisName := range chassises {
gwChassisName := lrp.Name + "-" + chassisName
gwChassis, err := ovnClient.GetGatewayChassis(gwChassisName, false)
require.NoError(t, err)
require.NotNil(t, gwChassis)
require.Equal(t, gwChassisName, gwChassis.Name)
require.Equal(t, chassisName, gwChassis.ChassisName)
require.Equal(t, 100-i, gwChassis.Priority)
Expand All @@ -49,18 +47,14 @@ func (suite *OvnClientTestSuite) testDeleteGatewayChassises() {
t.Parallel()

ovnClient := suite.ovnClient
lrName := "test-gateway-chassis-del-lr"
lrpName := "test-gateway-chassis-del-lrp"
chassises := []string{"ea8368a0-28cd-4549-9da5-a7ea67262619", "b25ffb94-8b32-4c7e-b5b0-0f343bf6bdd8", "62265268-8af7-4b36-a550-ab5ad38375e3"}

lrp := &ovnnb.LogicalRouterPort{
UUID: ovsclient.NamedUUID(),
Name: lrpName,
ExternalIDs: map[string]string{
"vendor": util.CniTypeName,
},
}
err := ovnClient.CreateLogicalRouter(lrName)
require.NoError(t, err)

err := createLogicalRouterPort(ovnClient, lrp)
err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"})
require.NoError(t, err)

err = ovnClient.CreateGatewayChassises(lrpName, chassises...)
Expand All @@ -69,6 +63,11 @@ func (suite *OvnClientTestSuite) testDeleteGatewayChassises() {
err = ovnClient.DeleteGatewayChassises(lrpName, append(chassises, "73bbe5d4-2b9b-47d0-aba8-94e86941881a"))
require.NoError(t, err)

lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false)
require.NoError(t, err)
require.NotNil(t, lrp)
require.Len(t, lrp.GatewayChassis, 0)

for _, chassisName := range chassises {
gwChassisName := lrpName + "-" + chassisName
_, err := ovnClient.GetGatewayChassis(gwChassisName, false)
Expand All @@ -81,19 +80,15 @@ func (suite *OvnClientTestSuite) testDeleteGatewayChassisOp() {
t.Parallel()

ovnClient := suite.ovnClient
lrName := "test-gateway-chassis-del-op-lr"
lrpName := "test-gateway-chassis-del-op-lrp"
chassis := "6c322ce8-02b7-42b3-925b-ae24020272a9"
gwChassisName := lrpName + "-" + chassis

lrp := &ovnnb.LogicalRouterPort{
UUID: ovsclient.NamedUUID(),
Name: lrpName,
ExternalIDs: map[string]string{
"vendor": util.CniTypeName,
},
}
err := ovnClient.CreateLogicalRouter(lrName)
require.NoError(t, err)

err := createLogicalRouterPort(ovnClient, lrp)
err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"})
require.NoError(t, err)

err = ovnClient.CreateGatewayChassises(lrpName, chassis)
Expand All @@ -102,18 +97,19 @@ func (suite *OvnClientTestSuite) testDeleteGatewayChassisOp() {
gwChassis, err := ovnClient.GetGatewayChassis(gwChassisName, false)
require.NoError(t, err)

ops, err := ovnClient.DeleteGatewayChassisOp(gwChassisName)
uuid, ops, err := ovnClient.DeleteGatewayChassisOp(gwChassisName)
require.NoError(t, err)
require.Equal(t, gwChassis.UUID, uuid)
require.Len(t, ops, 1)

require.Equal(t,
ovsdb.Operation{
Op: "delete",
Table: "Gateway_Chassis",
Op: ovsdb.OperationDelete,
Table: ovnnb.GatewayChassisTable,
Where: []ovsdb.Condition{
{
Column: "_uuid",
Function: "==",
Function: ovsdb.ConditionEqual,
Value: ovsdb.UUID{
GoUUID: gwChassis.UUID,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/ovs/ovn-nb-load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func (c *OVNNbClient) LoadBalancerDeleteHealthCheck(lbName, uuid string) error {
if len(ops) == 0 {
return nil
}
if err = c.Transact("lb-del", ops); err != nil {
if err = c.Transact("lb-hc-del", ops); err != nil {
return fmt.Errorf("failed to delete health check %s from load balancers %s: %v", uuid, lbName, err)
}
}
Expand Down
40 changes: 17 additions & 23 deletions pkg/ovs/ovn-nb-load_balancer_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package ovs
import (
"context"
"fmt"

"golang.org/x/exp/slices"
"slices"

"github.com/ovn-org/libovsdb/model"
"github.com/ovn-org/libovsdb/ovsdb"
Expand Down Expand Up @@ -129,12 +128,7 @@ func (c *OVNNbClient) UpdateLoadBalancerHealthCheck(lbhc *ovnnb.LoadBalancerHeal

// DeleteLoadBalancerHealthChecks delete several lb health checks once
func (c *OVNNbClient) DeleteLoadBalancerHealthChecks(filter func(lb *ovnnb.LoadBalancerHealthCheck) bool) error {
var (
op []ovsdb.Operation
err error
)

op, err = c.ovsDbClient.WhereCache(
op, err := c.ovsDbClient.WhereCache(
func(lbhc *ovnnb.LoadBalancerHealthCheck) bool {
if filter != nil {
return filter(lbhc)
Expand Down Expand Up @@ -178,12 +172,8 @@ func (c *OVNNbClient) GetLoadBalancerHealthCheck(lbName, vipEndpoint string, ign
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
defer cancel()

var (
lb *ovnnb.LoadBalancer
err error
)

if lb, err = c.GetLoadBalancer(lbName, false); err != nil {
lb, err := c.GetLoadBalancer(lbName, false)
if err != nil {
klog.Errorf("failed to get lb %s: %v", lbName, err)
return nil, nil, err
}
Expand Down Expand Up @@ -263,12 +253,7 @@ func (c *OVNNbClient) LoadBalancerHealthCheckExists(lbName, vipEndpoint string)

// DeleteLoadBalancerHealthCheckOp delete operation which delete lb health check
func (c *OVNNbClient) DeleteLoadBalancerHealthCheckOp(lbName, vip string) ([]ovsdb.Operation, error) {
var (
lbhc *ovnnb.LoadBalancerHealthCheck
err error
)

_, lbhc, err = c.GetLoadBalancerHealthCheck(lbName, vip, true)
lb, lbhc, err := c.GetLoadBalancerHealthCheck(lbName, vip, true)
if err != nil {
klog.Errorf("failed to get lb health check: %v", err)
return nil, err
Expand All @@ -278,11 +263,20 @@ func (c *OVNNbClient) DeleteLoadBalancerHealthCheckOp(lbName, vip string) ([]ovs
return nil, nil
}

var op []ovsdb.Operation
if op, err = c.Where(lbhc).Delete(); err != nil {
mutateOps, err := c.Where(lb).Mutate(lb, model.Mutation{
Field: &lb.HealthCheck,
Value: []string{lbhc.UUID},
Mutator: ovsdb.MutateOperationDelete,
})
if err != nil {
klog.Errorf("failed to generate operations for deleting lb health check: %v", err)
return nil, err
}
deleteOps, err := c.Where(lbhc).Delete()
if err != nil {
klog.Errorf("failed to generate operations for deleting lb health check: %v", err)
return nil, err
}

return op, nil
return append(mutateOps, deleteOps...), nil
}
Loading

0 comments on commit 3bfaf62

Please sign in to comment.