@@ -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 )
@@ -481,6 +498,11 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
481498 }
482499
483500 // handle policy route
501+ policyExternalIDs := map [string ]string {
502+ ovs .ExternalIDVendor : util .CniTypeName ,
503+ ovs .ExternalIDVpcPolicyRoute : "true" ,
504+ }
505+
484506 var (
485507 policyRouteExisted , policyRouteNeedDel , policyRouteNeedAdd []* kubeovnv1.PolicyRoute
486508 policyRouteLogical []* ovnnb.LogicalRouterPolicy
@@ -493,33 +515,30 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
493515 policyRouteNeedDel , policyRouteNeedAdd = diffPolicyRouteWithExisted (policyRouteExisted , vpc .Spec .PolicyRoutes )
494516 } else {
495517 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 )
518+ // only clean vpc spec managed policy routes, not those created by subnet or egress gateway controllers
519+ if err = c .OVNNbClient .DeleteLogicalRouterPolicies (vpc .Name , - 1 , policyExternalIDs ); err != nil {
520+ klog .Errorf ("clean vpc %s spec policy routes failed, %v" , vpc .Name , err )
499521 return err
500522 }
501523 } else {
502- policyRouteLogical , err = c .OVNNbClient .ListLogicalRouterPolicies (vpc .Name , - 1 , nil , true )
524+ policyRouteLogical , err = c .OVNNbClient .ListLogicalRouterPolicies (vpc .Name , - 1 , policyExternalIDs , false )
503525 if err != nil {
504526 klog .Errorf ("failed to get vpc %s policy route list, %v" , vpc .Name , err )
505527 return err
506528 }
507- // diff vpc policy route
508529 policyRouteNeedDel , policyRouteNeedAdd = diffPolicyRouteWithLogical (policyRouteLogical , vpc .Spec .PolicyRoutes )
509530 }
510531 }
511- // delete policies non-exist
512532 for _ , item := range policyRouteNeedDel {
513533 klog .Infof ("delete policy route for router: %s, priority: %d, match %s" , vpc .Name , item .Priority , item .Match )
514534 if err = c .OVNNbClient .DeleteLogicalRouterPolicy (vpc .Name , item .Priority , item .Match ); err != nil {
515535 klog .Errorf ("del vpc %s policy route failed, %v" , vpc .Name , err )
516536 return err
517537 }
518538 }
519- // add new policies
520539 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 {
540+ 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 )
541+ if err = c .OVNNbClient .AddLogicalRouterPolicy (vpc .Name , item .Priority , item .Match , string (item .Action ), []string {item .NextHopIP }, nil , policyExternalIDs ); err != nil {
523542 klog .Errorf ("add policy route to vpc %s failed, %v" , vpc .Name , err )
524543 return err
525544 }
@@ -580,7 +599,7 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
580599 if subnet .Spec .Vpc == key {
581600 // Accelerate subnet update when vpc config is updated.
582601 // 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 {
602+ if subnet .Status .IsNotReady () {
584603 c .addOrUpdateSubnetQueue .Add (subnet .Name )
585604 }
586605 if vpc .Name != util .DefaultVpc && vpc .Spec .EnableBfd && subnet .Spec .EnableEcmp {
0 commit comments