Skip to content

Commit 1adb28a

Browse files
authored
perf: only enqueue subnet when not ready (#6268)
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
1 parent 45e0afe commit 1adb28a

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

pkg/controller/vpc.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,23 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
459459
}
460460
}
461461
}
462+
} else {
463+
subnets, err := c.subnetsLister.List(labels.Everything())
464+
if err != nil {
465+
klog.Error(err)
466+
return err
467+
}
468+
// Add static routes created by addCustomVPCStaticRouteForSubnet
469+
for _, subnet := range subnets {
470+
if subnet.Spec.Vpc == key {
471+
staticTargetRoutes = append(staticTargetRoutes, &kubeovnv1.StaticRoute{
472+
Policy: kubeovnv1.PolicySrc,
473+
CIDR: subnet.Spec.CIDRBlock,
474+
NextHopIP: subnet.Spec.Gateway,
475+
RouteTable: subnet.Spec.RouteTable,
476+
})
477+
}
478+
}
462479
}
463480

464481
routeNeedDel, routeNeedAdd, err := diffStaticRoute(staticExistedRoutes, staticTargetRoutes)
@@ -508,21 +525,13 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
508525
// diff list
509526
policyRouteNeedDel, policyRouteNeedAdd = diffPolicyRouteWithExisted(policyRouteExisted, vpc.Spec.PolicyRoutes)
510527
} else {
511-
if vpc.Spec.PolicyRoutes == nil {
512-
// do not clean default vpc policy routes
513-
if err = c.OVNNbClient.ClearLogicalRouterPolicy(vpc.Name); err != nil {
514-
klog.Errorf("clean all vpc %s policy route failed, %v", vpc.Name, err)
515-
return err
516-
}
517-
} else {
518-
policyRouteLogical, err = c.OVNNbClient.ListLogicalRouterPolicies(vpc.Name, -1, nil, true)
519-
if err != nil {
520-
klog.Errorf("failed to get vpc %s policy route list, %v", vpc.Name, err)
521-
return err
522-
}
523-
// diff vpc policy route
524-
policyRouteNeedDel, policyRouteNeedAdd = diffPolicyRouteWithLogical(policyRouteLogical, vpc.Spec.PolicyRoutes)
528+
policyRouteLogical, err = c.OVNNbClient.ListLogicalRouterPolicies(vpc.Name, -1, nil, true)
529+
if err != nil {
530+
klog.Errorf("failed to get vpc %s policy route list, %v", vpc.Name, err)
531+
return err
525532
}
533+
// diff vpc policy route
534+
policyRouteNeedDel, policyRouteNeedAdd = diffPolicyRouteWithLogical(policyRouteLogical, vpc.Spec.PolicyRoutes)
526535
}
527536
// delete policies non-exist
528537
for _, item := range policyRouteNeedDel {
@@ -594,6 +603,11 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
594603
custVpcEnableExternalEcmp := false
595604
for _, subnet := range subnets {
596605
if subnet.Spec.Vpc == key {
606+
// Accelerate subnet update when vpc config is updated.
607+
// In case VPC not set namespaces, subnet will backoff and may take long time to back to ready.
608+
if subnet.Status.IsNotReady() {
609+
c.addOrUpdateSubnetQueue.Add(subnet.Name)
610+
}
597611
c.addOrUpdateSubnetQueue.Add(subnet.Name)
598612
if vpc.Name != util.DefaultVpc && vpc.Spec.EnableBfd && subnet.Spec.EnableEcmp {
599613
custVpcEnableExternalEcmp = true
@@ -1066,6 +1080,10 @@ func diffPolicyRouteWithLogical(exists []*ovnnb.LogicalRouterPolicy, target []*k
10661080
existsMap = make(map[string]*kubeovnv1.PolicyRoute, len(exists))
10671081

10681082
for _, item := range exists {
1083+
if item.ExternalIDs["vpc-egress-gateway"] != "" ||
1084+
item.ExternalIDs["isU2ORoutePolicy"] != "true" {
1085+
continue
1086+
}
10691087
policy := &kubeovnv1.PolicyRoute{
10701088
Priority: item.Priority,
10711089
Match: item.Match,

pkg/controller/vpc_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
108108
externalIDs,
109109
"10.0.0.1",
110110
).Return(nil)
111-
mockOvnClient.EXPECT().ClearLogicalRouterPolicy(vpcName).Return(nil)
111+
mockOvnClient.EXPECT().ListLogicalRouterPolicies(vpcName, -1, nil, true).Return(nil, nil)
112112
mockOvnClient.EXPECT().ListLogicalSwitch(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalSwitch{}, nil).AnyTimes()
113113
mockOvnClient.EXPECT().ListLogicalRouter(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalRouter{}, nil).AnyTimes()
114114
mockOvnClient.EXPECT().DeleteLogicalRouterPort(fmt.Sprintf("bfd@%s", vpcName)).Return(nil)
@@ -168,7 +168,7 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
168168
Nat: []string{},
169169
}, nil)
170170
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)
171+
mockOvnClient.EXPECT().ListLogicalRouterPolicies(vpcName, -1, nil, true).Return(nil, nil)
172172
mockOvnClient.EXPECT().ListLogicalSwitch(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalSwitch{}, nil).AnyTimes()
173173
mockOvnClient.EXPECT().ListLogicalRouter(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalRouter{}, nil).AnyTimes()
174174
mockOvnClient.EXPECT().DeleteLogicalRouterPort(fmt.Sprintf("bfd@%s", vpcName)).Return(nil)
@@ -222,7 +222,7 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
222222
}, nil)
223223
mockOvnClient.EXPECT().DeleteLogicalRouterStaticRoute(vpcName, gomock.Any(), gomock.Any(), "10.0.0.0/24", "1.2.3.4").Return(nil)
224224
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)
225+
mockOvnClient.EXPECT().ListLogicalRouterPolicies(vpcName, -1, nil, true).Return(nil, nil)
226226
mockOvnClient.EXPECT().ListLogicalSwitch(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalSwitch{}, nil).AnyTimes()
227227
mockOvnClient.EXPECT().ListLogicalRouter(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalRouter{}, nil).AnyTimes()
228228
mockOvnClient.EXPECT().DeleteLogicalRouterPort(fmt.Sprintf("bfd@%s", vpcName)).Return(nil)
@@ -285,7 +285,7 @@ func Test_handleAddOrUpdateVpc_staticRoutes(t *testing.T) {
285285
externalIDs,
286286
"10.0.0.1",
287287
).Return(nil)
288-
mockOvnClient.EXPECT().ClearLogicalRouterPolicy(vpcName).Return(nil)
288+
mockOvnClient.EXPECT().ListLogicalRouterPolicies(vpcName, -1, nil, true).Return(nil, nil)
289289
mockOvnClient.EXPECT().ListLogicalSwitch(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalSwitch{}, nil).AnyTimes()
290290
mockOvnClient.EXPECT().ListLogicalRouter(gomock.Any(), gomock.Any()).Return([]ovnnb.LogicalRouter{}, nil).AnyTimes()
291291
mockOvnClient.EXPECT().DeleteLogicalRouterPort(fmt.Sprintf("bfd@%s", vpcName)).Return(nil)

0 commit comments

Comments
 (0)