Skip to content

Commit

Permalink
support vip dual stack (kubeovn#3617)
Browse files Browse the repository at this point in the history
Signed-off-by: zcq98 <zhaocongqi_yewu@cmss.chinamobile.com>
Co-authored-by: zcq98 <zhaocongqi_yewu@cmss.chinamobile.com>
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
  • Loading branch information
zhangzujian and zcq98 committed Sep 4, 2024
1 parent 2960014 commit 0d8c1a9
Show file tree
Hide file tree
Showing 27 changed files with 691 additions and 576 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/emicklei/go-restful/v3 v3.12.1
github.com/evanphx/json-patch/v5 v5.9.0
github.com/go-logr/stdr v1.2.2
github.com/google/uuid v1.6.0
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.7.0
github.com/k8snetworkplumbingwg/sriovnet v1.2.0
github.com/kubeovn/felix v0.0.0-20240506083207-ed396be1b6cf
Expand Down Expand Up @@ -92,7 +93,6 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 // indirect
Expand Down Expand Up @@ -186,7 +186,7 @@ require (
replace (
github.com/mdlayher/arp => github.com/kubeovn/arp v0.0.0-20240218024213-d9612a263f68
github.com/openshift/client-go => github.com/openshift/client-go v0.0.1
github.com/ovn-org/libovsdb => github.com/kubeovn/libovsdb v0.0.0-20230517064328-9d5a1383643f
github.com/ovn-org/libovsdb => github.com/kubeovn/libovsdb v0.0.0-20240218023647-f0bc3ce57fcd
k8s.io/api => k8s.io/api v0.30.4
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.30.4
k8s.io/apimachinery => k8s.io/apimachinery v0.30.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,8 @@ github.com/kubeovn/go-iptables v0.0.0-20230322103850-8619a8ab3dca h1:fTMjoho2et9
github.com/kubeovn/go-iptables v0.0.0-20230322103850-8619a8ab3dca/go.mod h1:jY1XeGzkx8ASNJ+SqQSxTESNXARkjvt+I6IJOTnzIjw=
github.com/kubeovn/gonetworkmanager/v2 v2.0.0-20230905082151-e28c4d73a589 h1:y9exo1hjCsq7jsGUzt11kxhTiEGrGSQ0ZqibAiZk2PQ=
github.com/kubeovn/gonetworkmanager/v2 v2.0.0-20230905082151-e28c4d73a589/go.mod h1:49upX+/hUyppWIqu58cumojyIwXdkA8k6reA/mQlKuI=
github.com/kubeovn/libovsdb v0.0.0-20230517064328-9d5a1383643f h1:HDjnbJZN+2T3XH7usjtO2+PYDA2fyrLGYjypEA/87pM=
github.com/kubeovn/libovsdb v0.0.0-20230517064328-9d5a1383643f/go.mod h1:NHoQwGSKygdpFb8y7HBS6b1HP4EtJ14zzLrnd/A1fmY=
github.com/kubeovn/libovsdb v0.0.0-20240218023647-f0bc3ce57fcd h1:GhgvSBFKEkVNgDq8IslC04NVuoznreZH/Imz/cr6bhs=
github.com/kubeovn/libovsdb v0.0.0-20240218023647-f0bc3ce57fcd/go.mod h1:pTnlGt1JZrncr6pJn/Fhnp3FFTMQRaTVxiSKBLVGa5s=
github.com/kubeovn/ovsdb v0.0.0-20240410091831-5dd26006c475 h1:KZba2Kj9TXCUdUSqOR3eiy4VvkkIyhDVImYmYs6GQWU=
github.com/kubeovn/ovsdb v0.0.0-20240410091831-5dd26006c475/go.mod h1:LAd0qoeAAm/QyZcpxN2BnpndM2/dhZt+/kokPvcxKcE=
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 h1:nHHjmvjitIiyPlUHk/ofpgvBcNcawJLtf4PYHORLjAA=
Expand Down
28 changes: 28 additions & 0 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/ovs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type LogicalSwitch interface {

type LogicalSwitchPort interface {
CreateLogicalSwitchPort(lsName, lspName, ip, mac, podName, namespace string, portSecurity bool, securityGroups, vips string, enableDHCP bool, dhcpOptions *DHCPOptionsUUIDs, vpc string) error
CreateVirtualLogicalSwitchPort(lspName, lsName, ip string) error
CreateBareLogicalSwitchPort(lsName, lspName, ip, mac string) error
CreateLocalnetLogicalSwitchPort(lsName, lspName, provider, cidrBlock string, vlanID int) error
CreateVirtualLogicalSwitchPorts(lsName string, ips ...string) error
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 @@ -1407,7 +1407,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 @@ -1456,18 +1462,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
6 changes: 3 additions & 3 deletions pkg/ovs/ovn-nb-bfd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func (suite *OvnClientTestSuite) testDeleteBFD() {
t.Parallel()

ovnClient := suite.ovnClient
lrpName := "test-list-bfd"
dstIP1 := "192.168.124.1"
dstIP2 := "192.168.124.2"
lrpName := "test-del-bfd"
dstIP1 := "192.168.124.4"
dstIP2 := "192.168.124.5"
minRx1, minTx1, detectMult1 := 101, 102, 19
minRx2, minTx2, detectMult2 := 201, 202, 29

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 @@ -37,22 +37,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 @@ -160,23 +171,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 @@ -556,7 +556,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
Loading

0 comments on commit 0d8c1a9

Please sign in to comment.