@@ -468,21 +468,29 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
468468 // Add static routes created by addCustomVPCStaticRouteForSubnet
469469 for _ , subnet := range subnets {
470470 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- })
471+ v4Gw , v6Gw := util .SplitStringIP (subnet .Spec .Gateway )
472+ v4Cidr , v6Cidr := util .SplitStringIP (subnet .Spec .CIDRBlock )
473+ if v4Gw != "" && v4Cidr != "" {
474+ staticTargetRoutes = append (staticTargetRoutes , & kubeovnv1.StaticRoute {
475+ Policy : kubeovnv1 .PolicySrc ,
476+ CIDR : v4Cidr ,
477+ NextHopIP : v4Gw ,
478+ RouteTable : subnet .Spec .RouteTable ,
479+ })
480+ }
481+ if v6Gw != "" && v6Cidr != "" {
482+ staticTargetRoutes = append (staticTargetRoutes , & kubeovnv1.StaticRoute {
483+ Policy : kubeovnv1 .PolicySrc ,
484+ CIDR : v6Cidr ,
485+ NextHopIP : v6Gw ,
486+ RouteTable : subnet .Spec .RouteTable ,
487+ })
488+ }
477489 }
478490 }
479491 }
480492
481- routeNeedDel , routeNeedAdd , err := diffStaticRoute (staticExistedRoutes , staticTargetRoutes )
482- if err != nil {
483- klog .Errorf ("failed to diff vpc %s static route, %v" , vpc .Name , err )
484- return err
485- }
493+ routeNeedDel , routeNeedAdd := diffStaticRoute (staticExistedRoutes , staticTargetRoutes )
486494
487495 for _ , item := range routeNeedDel {
488496 klog .Infof ("vpc %s del static route: %+v" , vpc .Name , item )
@@ -608,7 +616,6 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
608616 if subnet .Status .IsNotReady () {
609617 c .addOrUpdateSubnetQueue .Add (subnet .Name )
610618 }
611- c .addOrUpdateSubnetQueue .Add (subnet .Name )
612619 if vpc .Name != util .DefaultVpc && vpc .Spec .EnableBfd && subnet .Spec .EnableEcmp {
613620 custVpcEnableExternalEcmp = true
614621 }
@@ -760,7 +767,7 @@ func (c *Controller) handleUpdateVpcExternal(vpc *kubeovnv1.Vpc, custVpcEnableEx
760767 }
761768 }
762769
763- if err := c .updateVpcExternalStatus (vpc .Name , vpc . Spec . EnableExternal ); err != nil {
770+ if err := c .updateVpcExternalStatus (vpc .Name ); err != nil {
764771 klog .Errorf ("failed to update vpc external subnets status, %v" , err )
765772 return err
766773 }
@@ -1015,11 +1022,13 @@ func diffPolicyRouteWithLogical(exists []*ovnnb.LogicalRouterPolicy, target []*k
10151022 key string
10161023 ok bool
10171024 )
1025+ klog .Infof ("diffPolicyRouteWithLogical exists: %v, target: %v" , exists , target )
10181026 existsMap = make (map [string ]* kubeovnv1.PolicyRoute , len (exists ))
10191027
10201028 for _ , item := range exists {
1021- if item .ExternalIDs ["vpc-egress-gateway" ] != "" ||
1022- item .ExternalIDs ["isU2ORoutePolicy" ] != "true" {
1029+ klog .Infof ("diffPolicyRouteWithLogical item: %+v" , item )
1030+ if item .ExternalIDs ["vpc-egress-gateway" ] != "" || item .ExternalIDs ["subnet" ] != "" ||
1031+ item .ExternalIDs ["isU2ORoutePolicy" ] == "true" {
10231032 continue
10241033 }
10251034 policy := & kubeovnv1.PolicyRoute {
@@ -1029,6 +1038,7 @@ func diffPolicyRouteWithLogical(exists []*ovnnb.LogicalRouterPolicy, target []*k
10291038 }
10301039 existsMap [getPolicyRouteItemKey (policy )] = policy
10311040 }
1041+ klog .Infof ("diffPolicyRouteWithLogical existsMap: %v" , existsMap )
10321042
10331043 for _ , item := range target {
10341044 key = getPolicyRouteItemKey (item )
@@ -1040,17 +1050,20 @@ func diffPolicyRouteWithLogical(exists []*ovnnb.LogicalRouterPolicy, target []*k
10401050 }
10411051 }
10421052
1053+ klog .Infof ("diffPolicyRouteWithLogical existsMap after delete: %v" , existsMap )
1054+
10431055 for _ , item := range existsMap {
10441056 dels = append (dels , item )
10451057 }
1058+ klog .Infof ("diffPolicyRouteWithLogical dels: %v, adds: %v" , dels , adds )
10461059 return dels , adds
10471060}
10481061
10491062func getPolicyRouteItemKey (item * kubeovnv1.PolicyRoute ) (key string ) {
10501063 return fmt .Sprintf ("%d:%s:%s:%s" , item .Priority , item .Match , item .Action , item .NextHopIP )
10511064}
10521065
1053- func diffStaticRoute (exist []* ovnnb.LogicalRouterStaticRoute , target []* kubeovnv1.StaticRoute ) (routeNeedDel , routeNeedAdd []* kubeovnv1.StaticRoute , err error ) {
1066+ func diffStaticRoute (exist []* ovnnb.LogicalRouterStaticRoute , target []* kubeovnv1.StaticRoute ) (routeNeedDel , routeNeedAdd []* kubeovnv1.StaticRoute ) {
10541067 existRouteMap := make (map [string ]* kubeovnv1.StaticRoute , len (exist ))
10551068 for _ , item := range exist {
10561069 policy := kubeovnv1 .PolicyDst
@@ -1081,7 +1094,7 @@ func diffStaticRoute(exist []*ovnnb.LogicalRouterStaticRoute, target []*kubeovnv
10811094 for _ , item := range existRouteMap {
10821095 routeNeedDel = append (routeNeedDel , item )
10831096 }
1084- return routeNeedDel , routeNeedAdd , err
1097+ return routeNeedDel , routeNeedAdd
10851098}
10861099
10871100func getStaticRouteItemKey (item * kubeovnv1.StaticRoute ) string {
@@ -1361,14 +1374,15 @@ func (c *Controller) handleDeleteVpcStaticRoute(key string) error {
13611374 needUpdate := false
13621375 newStaticRoutes := make ([]* kubeovnv1.StaticRoute , 0 , len (vpc .Spec .StaticRoutes ))
13631376 for _ , route := range vpc .Spec .StaticRoutes {
1364- if route .ECMPMode != util .StaticRouteBfdEcmp {
1365- newStaticRoutes = append (newStaticRoutes , route )
1377+ if route .ECMPMode == util .StaticRouteBfdEcmp {
13661378 needUpdate = true
1379+ continue
13671380 }
1381+ newStaticRoutes = append (newStaticRoutes , route )
13681382 }
1369- // keep non ecmp bfd routes
1370- vpc .Spec .StaticRoutes = newStaticRoutes
1383+ // keep routes except bfd ecmp routes
13711384 if needUpdate {
1385+ vpc .Spec .StaticRoutes = newStaticRoutes
13721386 if _ , err = c .config .KubeOvnClient .KubeovnV1 ().Vpcs ().Update (context .Background (), vpc , metav1.UpdateOptions {}); err != nil {
13731387 klog .Errorf ("failed to update vpc spec static route %s, %v" , vpc .Name , err )
13741388 return err
@@ -1438,7 +1452,7 @@ func (c *Controller) getRouteTablesByVpc(vpc *kubeovnv1.Vpc) map[string][]*kubeo
14381452 return rtbs
14391453}
14401454
1441- func (c * Controller ) updateVpcExternalStatus (key string , enableExternal bool ) error {
1455+ func (c * Controller ) updateVpcExternalStatus (key string ) error {
14421456 cachedVpc , err := c .vpcsLister .Get (key )
14431457 if err != nil {
14441458 klog .Errorf ("failed to get vpc %s, %v" , key , err )
@@ -1448,7 +1462,7 @@ func (c *Controller) updateVpcExternalStatus(key string, enableExternal bool) er
14481462 vpc .Status .EnableExternal = vpc .Spec .EnableExternal
14491463 vpc .Status .EnableBfd = vpc .Spec .EnableBfd
14501464
1451- if enableExternal {
1465+ if vpc . Spec . EnableExternal {
14521466 sort .Strings (vpc .Spec .ExtraExternalSubnets )
14531467 vpc .Status .ExtraExternalSubnets = vpc .Spec .ExtraExternalSubnets
14541468 } else {
0 commit comments