@@ -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,12 @@ 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 kube-ovn vendor and vpc-static-route label
2829 internalStaticRoute := & ovnnb.LogicalRouterStaticRoute {
2930 UUID : "internal-static-route-uuid" ,
3031 ExternalIDs : map [string ]string {
31- "vendor" : util .CniTypeName ,
32+ "vendor" : util .CniTypeName ,
33+ "vpc-static-route" : "true" ,
3234 },
3335 IPPrefix : "10.0.0.0/24" ,
3436 Nexthop : "1.2.3.4" ,
@@ -40,7 +42,8 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
4042 managedStaticRoute := & ovnnb.LogicalRouterStaticRoute {
4143 UUID : "managed-static-route-uuid" ,
4244 ExternalIDs : map [string ]string {
43- "vendor" : util .CniTypeName ,
45+ "vendor" : util .CniTypeName ,
46+ "vpc-static-route" : "true" ,
4447 },
4548 IPPrefix : "192.168.0.0/24" ,
4649 Nexthop : "10.0.0.1" ,
@@ -89,11 +92,14 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
8992 internalStaticRoute ,
9093 }
9194
92- externalIDs := map [string ]string {"vendor" : util .CniTypeName }
95+ staticRouteExternalIDs := map [string ]string {
96+ ovs .ExternalIDVendor : util .CniTypeName ,
97+ ovs .ExternalIDVpcStaticRoute : "true" ,
98+ }
9399
94100 mockOvnClient .EXPECT ().CreateLogicalRouter (vpcName ).Return (nil )
95101 mockOvnClient .EXPECT ().UpdateLogicalRouter (gomock .Any (), gomock .Any ()).Return (nil )
96- mockOvnClient .EXPECT ().ListLogicalRouterStaticRoutes (vpcName , nil , nil , "" , externalIDs ).Return (existingKubeOvnRoutes , nil )
102+ mockOvnClient .EXPECT ().ListLogicalRouterStaticRoutes (vpcName , nil , nil , "" , staticRouteExternalIDs ).Return (existingKubeOvnRoutes , nil )
97103 mockOvnClient .EXPECT ().GetLogicalRouter (vpcName , false ).Return (& ovnnb.LogicalRouter {
98104 Name : vpcName ,
99105 Nat : []string {},
@@ -105,10 +111,11 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
105111 "dst-ip" ,
106112 "192.168.0.0/24" ,
107113 nil ,
108- externalIDs ,
114+ staticRouteExternalIDs ,
109115 "10.0.0.1" ,
110116 ).Return (nil )
111- mockOvnClient .EXPECT ().ClearLogicalRouterPolicy (vpcName ).Return (nil )
117+ policyExternalIDs := map [string ]string {ovs .ExternalIDVendor : util .CniTypeName , ovs .ExternalIDVpcPolicyRoute : "true" }
118+ mockOvnClient .EXPECT ().DeleteLogicalRouterPolicies (vpcName , - 1 , policyExternalIDs ).Return (nil )
112119 mockOvnClient .EXPECT ().ListLogicalSwitch (gomock .Any (), gomock .Any ()).Return ([]ovnnb.LogicalSwitch {}, nil ).AnyTimes ()
113120 mockOvnClient .EXPECT ().ListLogicalRouter (gomock .Any (), gomock .Any ()).Return ([]ovnnb.LogicalRouter {}, nil ).AnyTimes ()
114121 mockOvnClient .EXPECT ().DeleteLogicalRouterPort (fmt .Sprintf ("bfd@%s" , vpcName )).Return (nil )
@@ -158,17 +165,21 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
158165 managedStaticRoute ,
159166 }
160167
161- externalIDs := map [string ]string {"vendor" : util .CniTypeName }
168+ staticRouteExternalIDs := map [string ]string {
169+ ovs .ExternalIDVendor : util .CniTypeName ,
170+ ovs .ExternalIDVpcStaticRoute : "true" ,
171+ }
162172
163173 mockOvnClient .EXPECT ().CreateLogicalRouter (vpcName ).Return (nil )
164174 mockOvnClient .EXPECT ().UpdateLogicalRouter (gomock .Any (), gomock .Any ()).Return (nil )
165- mockOvnClient .EXPECT ().ListLogicalRouterStaticRoutes (vpcName , nil , nil , "" , externalIDs ).Return (existingKubeOvnRoutes , nil )
175+ mockOvnClient .EXPECT ().ListLogicalRouterStaticRoutes (vpcName , nil , nil , "" , staticRouteExternalIDs ).Return (existingKubeOvnRoutes , nil )
166176 mockOvnClient .EXPECT ().GetLogicalRouter (vpcName , false ).Return (& ovnnb.LogicalRouter {
167177 Name : vpcName ,
168178 Nat : []string {},
169179 }, nil )
170180 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 )
181+ policyExternalIDs := map [string ]string {ovs .ExternalIDVendor : util .CniTypeName , ovs .ExternalIDVpcPolicyRoute : "true" }
182+ mockOvnClient .EXPECT ().DeleteLogicalRouterPolicies (vpcName , - 1 , policyExternalIDs ).Return (nil )
172183 mockOvnClient .EXPECT ().ListLogicalSwitch (gomock .Any (), gomock .Any ()).Return ([]ovnnb.LogicalSwitch {}, nil ).AnyTimes ()
173184 mockOvnClient .EXPECT ().ListLogicalRouter (gomock .Any (), gomock .Any ()).Return ([]ovnnb.LogicalRouter {}, nil ).AnyTimes ()
174185 mockOvnClient .EXPECT ().DeleteLogicalRouterPort (fmt .Sprintf ("bfd@%s" , vpcName )).Return (nil )
@@ -211,18 +222,22 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
211222 managedStaticRoute ,
212223 }
213224
214- externalIDs := map [string ]string {"vendor" : util .CniTypeName }
225+ staticRouteExternalIDs := map [string ]string {
226+ ovs .ExternalIDVendor : util .CniTypeName ,
227+ ovs .ExternalIDVpcStaticRoute : "true" ,
228+ }
215229
216230 mockOvnClient .EXPECT ().CreateLogicalRouter (vpcName ).Return (nil )
217231 mockOvnClient .EXPECT ().UpdateLogicalRouter (gomock .Any (), gomock .Any ()).Return (nil )
218- mockOvnClient .EXPECT ().ListLogicalRouterStaticRoutes (vpcName , nil , nil , "" , externalIDs ).Return (existingKubeOvnRoutes , nil )
232+ mockOvnClient .EXPECT ().ListLogicalRouterStaticRoutes (vpcName , nil , nil , "" , staticRouteExternalIDs ).Return (existingKubeOvnRoutes , nil )
219233 mockOvnClient .EXPECT ().GetLogicalRouter (vpcName , false ).Return (& ovnnb.LogicalRouter {
220234 Name : vpcName ,
221235 Nat : []string {},
222236 }, nil )
223237 mockOvnClient .EXPECT ().DeleteLogicalRouterStaticRoute (vpcName , gomock .Any (), gomock .Any (), "10.0.0.0/24" , "1.2.3.4" ).Return (nil )
224238 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 )
239+ policyExternalIDs := map [string ]string {ovs .ExternalIDVendor : util .CniTypeName , ovs .ExternalIDVpcPolicyRoute : "true" }
240+ mockOvnClient .EXPECT ().DeleteLogicalRouterPolicies (vpcName , - 1 , policyExternalIDs ).Return (nil )
226241 mockOvnClient .EXPECT ().ListLogicalSwitch (gomock .Any (), gomock .Any ()).Return ([]ovnnb.LogicalSwitch {}, nil ).AnyTimes ()
227242 mockOvnClient .EXPECT ().ListLogicalRouter (gomock .Any (), gomock .Any ()).Return ([]ovnnb.LogicalRouter {}, nil ).AnyTimes ()
228243 mockOvnClient .EXPECT ().DeleteLogicalRouterPort (fmt .Sprintf ("bfd@%s" , vpcName )).Return (nil )
@@ -267,11 +282,14 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
267282 err = fakeinformers .vpcInformer .Informer ().GetStore ().Add (vpc )
268283 require .NoError (t , err )
269284
270- externalIDs := map [string ]string {"vendor" : util .CniTypeName }
285+ staticRouteExternalIDs := map [string ]string {
286+ ovs .ExternalIDVendor : util .CniTypeName ,
287+ ovs .ExternalIDVpcStaticRoute : "true" ,
288+ }
271289
272290 mockOvnClient .EXPECT ().CreateLogicalRouter (vpcName ).Return (nil )
273291 mockOvnClient .EXPECT ().UpdateLogicalRouter (gomock .Any (), gomock .Any ()).Return (nil )
274- mockOvnClient .EXPECT ().ListLogicalRouterStaticRoutes (vpcName , nil , nil , "" , externalIDs ).Return (nil , nil )
292+ mockOvnClient .EXPECT ().ListLogicalRouterStaticRoutes (vpcName , nil , nil , "" , staticRouteExternalIDs ).Return (nil , nil )
275293 mockOvnClient .EXPECT ().GetLogicalRouter (vpcName , false ).Return (& ovnnb.LogicalRouter {
276294 Name : vpcName ,
277295 Nat : []string {},
@@ -282,10 +300,11 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
282300 "dst-ip" ,
283301 "192.168.0.0/24" ,
284302 nil ,
285- externalIDs ,
303+ staticRouteExternalIDs ,
286304 "10.0.0.1" ,
287305 ).Return (nil )
288- mockOvnClient .EXPECT ().ClearLogicalRouterPolicy (vpcName ).Return (nil )
306+ policyExternalIDs := map [string ]string {ovs .ExternalIDVendor : util .CniTypeName , ovs .ExternalIDVpcPolicyRoute : "true" }
307+ mockOvnClient .EXPECT ().DeleteLogicalRouterPolicies (vpcName , - 1 , policyExternalIDs ).Return (nil )
289308 mockOvnClient .EXPECT ().ListLogicalSwitch (gomock .Any (), gomock .Any ()).Return ([]ovnnb.LogicalSwitch {}, nil ).AnyTimes ()
290309 mockOvnClient .EXPECT ().ListLogicalRouter (gomock .Any (), gomock .Any ()).Return ([]ovnnb.LogicalRouter {}, nil ).AnyTimes ()
291310 mockOvnClient .EXPECT ().DeleteLogicalRouterPort (fmt .Sprintf ("bfd@%s" , vpcName )).Return (nil )
0 commit comments