Skip to content

Commit 4e98779

Browse files
committed
fix: use external_ids to identify vpc policy routes and static routes
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
1 parent f6c95e8 commit 4e98779

File tree

5 files changed

+140
-42
lines changed

5 files changed

+140
-42
lines changed

pkg/controller/node.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,8 @@ func (c *Controller) addNodeGatewayStaticRoute() error {
945945
NextHopIP: nextHop,
946946
RouteTable: util.MainRouteTable,
947947
},
948+
"node",
949+
"node-gateway",
948950
); err != nil {
949951
klog.Errorf("failed to add static route for node gw: %v", err)
950952
return err

pkg/controller/subnet.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,6 +2498,8 @@ func (c *Controller) addCustomVPCStaticRouteForSubnet(subnet *kubeovnv1.Subnet)
24982498
CIDR: v4Cidr,
24992499
NextHopIP: v4Gw,
25002500
},
2501+
"subnet",
2502+
subnet.Name,
25012503
); err != nil {
25022504
klog.Errorf("failed to add static route, %v", err)
25032505
return err
@@ -2512,6 +2514,8 @@ func (c *Controller) addCustomVPCStaticRouteForSubnet(subnet *kubeovnv1.Subnet)
25122514
CIDR: v6Cidr,
25132515
NextHopIP: v6Gw,
25142516
},
2517+
"subnet",
2518+
subnet.Name,
25152519
); err != nil {
25162520
klog.Errorf("failed to add static route, %v", err)
25172521
return err

pkg/controller/vpc.go

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2525

2626
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
27+
"github.com/kubeovn/kube-ovn/pkg/ovs"
2728
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
2829
"github.com/kubeovn/kube-ovn/pkg/util"
2930
)
@@ -289,7 +290,23 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
289290
return err
290291
}
291292

292-
learnFromARPRequest := true
293+
learnFromARPRequest := vpc.Spec.EnableExternal
294+
if !learnFromARPRequest {
295+
for _, subnetName := range vpc.Status.Subnets {
296+
subnet, err := c.subnetsLister.Get(subnetName)
297+
if err != nil {
298+
if k8serrors.IsNotFound(err) {
299+
continue
300+
}
301+
klog.Errorf("failed to get subnet %s for vpc %s: %v", subnetName, key, err)
302+
return err
303+
}
304+
if subnet.Spec.Vlan != "" && subnet.Spec.U2OInterconnection {
305+
learnFromARPRequest = true
306+
break
307+
}
308+
}
309+
}
293310

294311
if err = c.createVpcRouter(key, learnFromARPRequest); err != nil {
295312
klog.Errorf("failed to create vpc router for vpc %s: %v", key, err)
@@ -319,20 +336,36 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
319336
}
320337

321338
// handle static route
339+
staticRouteExternalIDs := map[string]string{
340+
ovs.ExternalIDVendor: util.CniTypeName,
341+
ovs.ExternalIDController: "vpc",
342+
ovs.ExternalIDResourceName: vpc.Name,
343+
}
344+
322345
var (
323346
staticExistedRoutes []*ovnnb.LogicalRouterStaticRoute
324347
staticTargetRoutes []*kubeovnv1.StaticRoute
325348
staticRouteMapping map[string][]*kubeovnv1.StaticRoute
326-
externalIDs = map[string]string{"vendor": util.CniTypeName}
327349
)
328350

329-
// only manage static routes which are kube-ovn managed, by filtering for vendor util.CniTypeName
330-
staticExistedRoutes, err = c.OVNNbClient.ListLogicalRouterStaticRoutes(vpc.Name, nil, nil, "", externalIDs)
351+
newFormatRoutes, err := c.OVNNbClient.ListLogicalRouterStaticRoutes(vpc.Name, nil, nil, "", staticRouteExternalIDs)
331352
if err != nil {
332-
klog.Errorf("failed to get vpc %s static route list, %v", vpc.Name, err)
353+
klog.Errorf("failed to get vpc %s static route list with new format, %v", vpc.Name, err)
333354
return err
334355
}
335356

357+
oldFormatExternalIDs := map[string]string{
358+
ovs.ExternalIDVendor: util.CniTypeName,
359+
ovs.ExternalIDVpcStaticRoute: "true",
360+
}
361+
oldFormatRoutes, err := c.OVNNbClient.ListLogicalRouterStaticRoutes(vpc.Name, nil, nil, "", oldFormatExternalIDs)
362+
if err != nil {
363+
klog.Errorf("failed to get vpc %s static route list with old format, %v", vpc.Name, err)
364+
return err
365+
}
366+
367+
staticExistedRoutes = append(newFormatRoutes, oldFormatRoutes...)
368+
336369
var externalSubnet *kubeovnv1.Subnet
337370
externalSubnetExist := false
338371
externalSubnetGW := ""
@@ -464,15 +497,15 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
464497
if item.BfdID != "" {
465498
klog.Infof("vpc %s add static ecmp route: %+v", vpc.Name, item)
466499
if err = c.OVNNbClient.AddLogicalRouterStaticRoute(
467-
vpc.Name, item.RouteTable, convertPolicy(item.Policy), item.CIDR, &item.BfdID, externalIDs, item.NextHopIP,
500+
vpc.Name, item.RouteTable, convertPolicy(item.Policy), item.CIDR, &item.BfdID, staticRouteExternalIDs, item.NextHopIP,
468501
); err != nil {
469502
klog.Errorf("failed to add bfd static route to vpc %s , %v", vpc.Name, err)
470503
return err
471504
}
472505
} else {
473506
klog.Infof("vpc %s add static route: %+v", vpc.Name, item)
474507
if err = c.OVNNbClient.AddLogicalRouterStaticRoute(
475-
vpc.Name, item.RouteTable, convertPolicy(item.Policy), item.CIDR, nil, externalIDs, item.NextHopIP,
508+
vpc.Name, item.RouteTable, convertPolicy(item.Policy), item.CIDR, nil, staticRouteExternalIDs, item.NextHopIP,
476509
); err != nil {
477510
klog.Errorf("failed to add normal static route to vpc %s , %v", vpc.Name, err)
478511
return err
@@ -481,6 +514,11 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
481514
}
482515

483516
// handle policy route
517+
policyExternalIDs := map[string]string{
518+
ovs.ExternalIDVendor: util.CniTypeName,
519+
ovs.ExternalIDVpcPolicyRoute: "true",
520+
}
521+
484522
var (
485523
policyRouteExisted, policyRouteNeedDel, policyRouteNeedAdd []*kubeovnv1.PolicyRoute
486524
policyRouteLogical []*ovnnb.LogicalRouterPolicy
@@ -493,33 +531,30 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
493531
policyRouteNeedDel, policyRouteNeedAdd = diffPolicyRouteWithExisted(policyRouteExisted, vpc.Spec.PolicyRoutes)
494532
} else {
495533
if vpc.Spec.PolicyRoutes == nil {
496-
// do not clean default vpc policy routes
497-
if err = c.OVNNbClient.ClearLogicalRouterPolicy(vpc.Name); err != nil {
498-
klog.Errorf("clean all vpc %s policy route failed, %v", vpc.Name, err)
534+
// only clean vpc spec managed policy routes, not those created by subnet or egress gateway controllers
535+
if err = c.OVNNbClient.DeleteLogicalRouterPolicies(vpc.Name, -1, policyExternalIDs); err != nil {
536+
klog.Errorf("clean vpc %s spec policy routes failed, %v", vpc.Name, err)
499537
return err
500538
}
501539
} else {
502-
policyRouteLogical, err = c.OVNNbClient.ListLogicalRouterPolicies(vpc.Name, -1, nil, true)
540+
policyRouteLogical, err = c.OVNNbClient.ListLogicalRouterPolicies(vpc.Name, -1, policyExternalIDs, false)
503541
if err != nil {
504542
klog.Errorf("failed to get vpc %s policy route list, %v", vpc.Name, err)
505543
return err
506544
}
507-
// diff vpc policy route
508545
policyRouteNeedDel, policyRouteNeedAdd = diffPolicyRouteWithLogical(policyRouteLogical, vpc.Spec.PolicyRoutes)
509546
}
510547
}
511-
// delete policies non-exist
512548
for _, item := range policyRouteNeedDel {
513549
klog.Infof("delete policy route for router: %s, priority: %d, match %s", vpc.Name, item.Priority, item.Match)
514550
if err = c.OVNNbClient.DeleteLogicalRouterPolicy(vpc.Name, item.Priority, item.Match); err != nil {
515551
klog.Errorf("del vpc %s policy route failed, %v", vpc.Name, err)
516552
return err
517553
}
518554
}
519-
// add new policies
520555
for _, item := range policyRouteNeedAdd {
521-
klog.Infof("add policy route for router: %s, match %s, action %s, nexthop %s, externalID %v", c.config.ClusterRouter, item.Match, string(item.Action), item.NextHopIP, externalIDs)
522-
if err = c.OVNNbClient.AddLogicalRouterPolicy(vpc.Name, item.Priority, item.Match, string(item.Action), []string{item.NextHopIP}, nil, externalIDs); err != nil {
556+
klog.Infof("add policy route for router: %s, match %s, action %s, nexthop %s, externalID %v", vpc.Name, item.Match, string(item.Action), item.NextHopIP, policyExternalIDs)
557+
if err = c.OVNNbClient.AddLogicalRouterPolicy(vpc.Name, item.Priority, item.Match, string(item.Action), []string{item.NextHopIP}, nil, policyExternalIDs); err != nil {
523558
klog.Errorf("add policy route to vpc %s failed, %v", vpc.Name, err)
524559
return err
525560
}
@@ -580,7 +615,7 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
580615
if subnet.Spec.Vpc == key {
581616
// Accelerate subnet update when vpc config is updated.
582617
// In case VPC not set namespaces, subnet will backoff and may take long time to back to ready.
583-
if subnet.Status.IsNotReady() || subnet.Spec.U2OInterconnection {
618+
if subnet.Status.IsNotReady() {
584619
c.addOrUpdateSubnetQueue.Add(subnet.Name)
585620
}
586621
if vpc.Name != util.DefaultVpc && vpc.Spec.EnableBfd && subnet.Spec.EnableEcmp {
@@ -936,22 +971,26 @@ func (c *Controller) batchDeletePolicyRouteFromVpc(name string, policies []*kube
936971
return nil
937972
}
938973

939-
func (c *Controller) addStaticRouteToVpc(name string, route *kubeovnv1.StaticRoute) error {
940-
externalIDs := map[string]string{"vendor": util.CniTypeName}
974+
func (c *Controller) addStaticRouteToVpc(vpcName string, route *kubeovnv1.StaticRoute, controller, resourceName string) error {
975+
externalIDs := map[string]string{
976+
ovs.ExternalIDVendor: util.CniTypeName,
977+
ovs.ExternalIDController: controller,
978+
ovs.ExternalIDResourceName: resourceName,
979+
}
941980
if route.BfdID != "" {
942-
klog.Infof("vpc %s add static ecmp route: %+v", name, route)
981+
klog.Infof("vpc %s add static ecmp route: %+v", vpcName, route)
943982
if err := c.OVNNbClient.AddLogicalRouterStaticRoute(
944-
name, route.RouteTable, convertPolicy(route.Policy), route.CIDR, &route.BfdID, externalIDs, route.NextHopIP,
983+
vpcName, route.RouteTable, convertPolicy(route.Policy), route.CIDR, &route.BfdID, externalIDs, route.NextHopIP,
945984
); err != nil {
946-
klog.Errorf("failed to add bfd static route to vpc %s , %v", name, err)
985+
klog.Errorf("failed to add bfd static route to vpc %s , %v", vpcName, err)
947986
return err
948987
}
949988
} else {
950-
klog.Infof("vpc %s add static route: %+v", name, route)
989+
klog.Infof("vpc %s add static route: %+v", vpcName, route)
951990
if err := c.OVNNbClient.AddLogicalRouterStaticRoute(
952-
name, route.RouteTable, convertPolicy(route.Policy), route.CIDR, nil, externalIDs, route.NextHopIP,
991+
vpcName, route.RouteTable, convertPolicy(route.Policy), route.CIDR, nil, externalIDs, route.NextHopIP,
953992
); err != nil {
954-
klog.Errorf("failed to add normal static route to vpc %s , %v", name, err)
993+
klog.Errorf("failed to add normal static route to vpc %s , %v", vpcName, err)
955994
return err
956995
}
957996
}

pkg/controller/vpc_test.go

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"k8s.io/utils/keymutex"
1212

1313
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
14+
"github.com/kubeovn/kube-ovn/pkg/ovs"
1415
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
1516
"github.com/kubeovn/kube-ovn/pkg/util"
1617
)
@@ -24,11 +25,13 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
2425
srcIPPolicy := ovnnb.LogicalRouterStaticRoutePolicySrcIP
2526
dstIPPolicy := ovnnb.LogicalRouterStaticRoutePolicyDstIP
2627

27-
// Internal static route created directly in OVN with kube-ovn vendor
28+
// Internal static route created directly in OVN with fine-grained labels
2829
internalStaticRoute := &ovnnb.LogicalRouterStaticRoute{
2930
UUID: "internal-static-route-uuid",
3031
ExternalIDs: map[string]string{
31-
"vendor": util.CniTypeName,
32+
"vendor": util.CniTypeName,
33+
"controller": "vpc",
34+
"resource-name": "test-vpc",
3235
},
3336
IPPrefix: "10.0.0.0/24",
3437
Nexthop: "1.2.3.4",
@@ -40,7 +43,9 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
4043
managedStaticRoute := &ovnnb.LogicalRouterStaticRoute{
4144
UUID: "managed-static-route-uuid",
4245
ExternalIDs: map[string]string{
43-
"vendor": util.CniTypeName,
46+
"vendor": util.CniTypeName,
47+
"controller": "vpc",
48+
"resource-name": "test-vpc",
4449
},
4550
IPPrefix: "192.168.0.0/24",
4651
Nexthop: "10.0.0.1",
@@ -89,11 +94,21 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
8994
internalStaticRoute,
9095
}
9196

92-
externalIDs := map[string]string{"vendor": util.CniTypeName}
97+
staticRouteExternalIDs := map[string]string{
98+
ovs.ExternalIDVendor: util.CniTypeName,
99+
ovs.ExternalIDController: "vpc",
100+
ovs.ExternalIDResourceName: vpcName,
101+
}
102+
103+
oldFormatExternalIDs := map[string]string{
104+
ovs.ExternalIDVendor: util.CniTypeName,
105+
ovs.ExternalIDVpcStaticRoute: "true",
106+
}
93107

94108
mockOvnClient.EXPECT().CreateLogicalRouter(vpcName).Return(nil)
95109
mockOvnClient.EXPECT().UpdateLogicalRouter(gomock.Any(), gomock.Any()).Return(nil)
96-
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", externalIDs).Return(existingKubeOvnRoutes, nil)
110+
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", staticRouteExternalIDs).Return(existingKubeOvnRoutes, nil)
111+
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", oldFormatExternalIDs).Return(nil, nil)
97112
mockOvnClient.EXPECT().GetLogicalRouter(vpcName, false).Return(&ovnnb.LogicalRouter{
98113
Name: vpcName,
99114
Nat: []string{},
@@ -105,10 +120,11 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
105120
"dst-ip",
106121
"192.168.0.0/24",
107122
nil,
108-
externalIDs,
123+
staticRouteExternalIDs,
109124
"10.0.0.1",
110125
).Return(nil)
111-
mockOvnClient.EXPECT().ClearLogicalRouterPolicy(vpcName).Return(nil)
126+
policyExternalIDs := map[string]string{ovs.ExternalIDVendor: util.CniTypeName, ovs.ExternalIDVpcPolicyRoute: "true"}
127+
mockOvnClient.EXPECT().DeleteLogicalRouterPolicies(vpcName, -1, policyExternalIDs).Return(nil)
112128
mockOvnClient.EXPECT().ListLogicalSwitch(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalSwitch{}, nil).AnyTimes()
113129
mockOvnClient.EXPECT().ListLogicalRouter(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalRouter{}, nil).AnyTimes()
114130
mockOvnClient.EXPECT().DeleteLogicalRouterPort(fmt.Sprintf("bfd@%s", vpcName)).Return(nil)
@@ -158,17 +174,28 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
158174
managedStaticRoute,
159175
}
160176

161-
externalIDs := map[string]string{"vendor": util.CniTypeName}
177+
staticRouteExternalIDs := map[string]string{
178+
ovs.ExternalIDVendor: util.CniTypeName,
179+
ovs.ExternalIDController: "vpc",
180+
ovs.ExternalIDResourceName: vpcName,
181+
}
182+
183+
oldFormatExternalIDs := map[string]string{
184+
ovs.ExternalIDVendor: util.CniTypeName,
185+
ovs.ExternalIDVpcStaticRoute: "true",
186+
}
162187

163188
mockOvnClient.EXPECT().CreateLogicalRouter(vpcName).Return(nil)
164189
mockOvnClient.EXPECT().UpdateLogicalRouter(gomock.Any(), gomock.Any()).Return(nil)
165-
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", externalIDs).Return(existingKubeOvnRoutes, nil)
190+
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", staticRouteExternalIDs).Return(existingKubeOvnRoutes, nil)
191+
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", oldFormatExternalIDs).Return(nil, nil)
166192
mockOvnClient.EXPECT().GetLogicalRouter(vpcName, false).Return(&ovnnb.LogicalRouter{
167193
Name: vpcName,
168194
Nat: []string{},
169195
}, nil)
170196
mockOvnClient.EXPECT().DeleteLogicalRouterStaticRoute(vpcName, gomock.Any(), gomock.Any(), "10.0.0.0/24", "1.2.3.4").Return(nil)
171-
mockOvnClient.EXPECT().ClearLogicalRouterPolicy(vpcName).Return(nil)
197+
policyExternalIDs := map[string]string{ovs.ExternalIDVendor: util.CniTypeName, ovs.ExternalIDVpcPolicyRoute: "true"}
198+
mockOvnClient.EXPECT().DeleteLogicalRouterPolicies(vpcName, -1, policyExternalIDs).Return(nil)
172199
mockOvnClient.EXPECT().ListLogicalSwitch(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalSwitch{}, nil).AnyTimes()
173200
mockOvnClient.EXPECT().ListLogicalRouter(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalRouter{}, nil).AnyTimes()
174201
mockOvnClient.EXPECT().DeleteLogicalRouterPort(fmt.Sprintf("bfd@%s", vpcName)).Return(nil)
@@ -211,18 +238,29 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
211238
managedStaticRoute,
212239
}
213240

214-
externalIDs := map[string]string{"vendor": util.CniTypeName}
241+
staticRouteExternalIDs := map[string]string{
242+
ovs.ExternalIDVendor: util.CniTypeName,
243+
ovs.ExternalIDController: "vpc",
244+
ovs.ExternalIDResourceName: vpcName,
245+
}
246+
247+
oldFormatExternalIDs := map[string]string{
248+
ovs.ExternalIDVendor: util.CniTypeName,
249+
ovs.ExternalIDVpcStaticRoute: "true",
250+
}
215251

216252
mockOvnClient.EXPECT().CreateLogicalRouter(vpcName).Return(nil)
217253
mockOvnClient.EXPECT().UpdateLogicalRouter(gomock.Any(), gomock.Any()).Return(nil)
218-
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", externalIDs).Return(existingKubeOvnRoutes, nil)
254+
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", staticRouteExternalIDs).Return(existingKubeOvnRoutes, nil)
255+
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", oldFormatExternalIDs).Return(nil, nil)
219256
mockOvnClient.EXPECT().GetLogicalRouter(vpcName, false).Return(&ovnnb.LogicalRouter{
220257
Name: vpcName,
221258
Nat: []string{},
222259
}, nil)
223260
mockOvnClient.EXPECT().DeleteLogicalRouterStaticRoute(vpcName, gomock.Any(), gomock.Any(), "10.0.0.0/24", "1.2.3.4").Return(nil)
224261
mockOvnClient.EXPECT().DeleteLogicalRouterStaticRoute(vpcName, gomock.Any(), gomock.Any(), "192.168.0.0/24", "10.0.0.1").Return(nil)
225-
mockOvnClient.EXPECT().ClearLogicalRouterPolicy(vpcName).Return(nil)
262+
policyExternalIDs := map[string]string{ovs.ExternalIDVendor: util.CniTypeName, ovs.ExternalIDVpcPolicyRoute: "true"}
263+
mockOvnClient.EXPECT().DeleteLogicalRouterPolicies(vpcName, -1, policyExternalIDs).Return(nil)
226264
mockOvnClient.EXPECT().ListLogicalSwitch(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalSwitch{}, nil).AnyTimes()
227265
mockOvnClient.EXPECT().ListLogicalRouter(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalRouter{}, nil).AnyTimes()
228266
mockOvnClient.EXPECT().DeleteLogicalRouterPort(fmt.Sprintf("bfd@%s", vpcName)).Return(nil)
@@ -267,11 +305,21 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
267305
err = fakeinformers.vpcInformer.Informer().GetStore().Add(vpc)
268306
require.NoError(t, err)
269307

270-
externalIDs := map[string]string{"vendor": util.CniTypeName}
308+
staticRouteExternalIDs := map[string]string{
309+
ovs.ExternalIDVendor: util.CniTypeName,
310+
ovs.ExternalIDController: "vpc",
311+
ovs.ExternalIDResourceName: vpcName,
312+
}
313+
314+
oldFormatExternalIDs := map[string]string{
315+
ovs.ExternalIDVendor: util.CniTypeName,
316+
ovs.ExternalIDVpcStaticRoute: "true",
317+
}
271318

272319
mockOvnClient.EXPECT().CreateLogicalRouter(vpcName).Return(nil)
273320
mockOvnClient.EXPECT().UpdateLogicalRouter(gomock.Any(), gomock.Any()).Return(nil)
274-
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", externalIDs).Return(nil, nil)
321+
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", staticRouteExternalIDs).Return(nil, nil)
322+
mockOvnClient.EXPECT().ListLogicalRouterStaticRoutes(vpcName, nil, nil, "", oldFormatExternalIDs).Return(nil, nil)
275323
mockOvnClient.EXPECT().GetLogicalRouter(vpcName, false).Return(&ovnnb.LogicalRouter{
276324
Name: vpcName,
277325
Nat: []string{},
@@ -282,10 +330,11 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
282330
"dst-ip",
283331
"192.168.0.0/24",
284332
nil,
285-
externalIDs,
333+
staticRouteExternalIDs,
286334
"10.0.0.1",
287335
).Return(nil)
288-
mockOvnClient.EXPECT().ClearLogicalRouterPolicy(vpcName).Return(nil)
336+
policyExternalIDs := map[string]string{ovs.ExternalIDVendor: util.CniTypeName, ovs.ExternalIDVpcPolicyRoute: "true"}
337+
mockOvnClient.EXPECT().DeleteLogicalRouterPolicies(vpcName, -1, policyExternalIDs).Return(nil)
289338
mockOvnClient.EXPECT().ListLogicalSwitch(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalSwitch{}, nil).AnyTimes()
290339
mockOvnClient.EXPECT().ListLogicalRouter(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalRouter{}, nil).AnyTimes()
291340
mockOvnClient.EXPECT().DeleteLogicalRouterPort(fmt.Sprintf("bfd@%s", vpcName)).Return(nil)

0 commit comments

Comments
 (0)