@@ -177,6 +177,15 @@ func (tn testNeighbor) Neighbor() frrapi.Neighbor {
177177 if sep == - 1 {
178178 continue
179179 }
180+ if isLayer2 := strings .Count (receive , "/" ) == 1 ; isLayer2 {
181+ n .ToReceive .Allowed .Prefixes = append (n .ToReceive .Allowed .Prefixes ,
182+ frrapi.PrefixSelector {
183+ Prefix : receive ,
184+ },
185+ )
186+ continue
187+ }
188+
180189 first := receive [:sep ]
181190 last := receive [sep + 1 :]
182191 len := ovntest .MustAtoi (last )
@@ -314,9 +323,6 @@ func (tn testNAD) NAD() *nadtypes.NetworkAttachmentDefinition {
314323 nad .ObjectMeta .OwnerReferences = []metav1.OwnerReference {ownerRef }
315324 }
316325 topology := tn .Topology
317- if topology == "" {
318- topology = "layer3"
319- }
320326 switch {
321327 case tn .IsSecondary :
322328 nad .Spec .Config = fmt .Sprintf ("{\" cniVersion\" : \" 0.4.0\" , \" name\" : \" %s\" , \" type\" : \" %s\" , \" topology\" : \" %s\" , \" netAttachDefName\" : \" %s\" , \" subnets\" : \" %s\" }" ,
@@ -477,8 +483,10 @@ func TestController_reconcile(t *testing.T) {
477483 },
478484 },
479485 nads : []* testNAD {
480- {Name : "red" , Namespace : "red" , Network : "cluster_udn_red" , Topology : "layer3" , Subnet : "1.2.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
481- {Name : "blue" , Namespace : "blue" , Network : "cluster_udn_blue" , Topology : "layer3" , Subnet : "1.3.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
486+ {Name : "red" , Namespace : "red" , Network : util .GenerateCUDNNetworkName ("red" ), Topology : "layer3" , Subnet : "1.2.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
487+ {Name : "blue" , Namespace : "blue" , Network : util .GenerateCUDNNetworkName ("blue" ), Topology : "layer3" , Subnet : "1.3.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
488+ {Name : "green" , Namespace : "green" , Network : util .GenerateCUDNNetworkName ("green" ), Topology : "layer2" , Subnet : "1.4.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
489+ {Name : "black" , Namespace : "black" , Network : util .GenerateCUDNNetworkName ("black" ), Topology : "layer2" , Subnet : "1.5.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
482490 },
483491 nodes : []* testNode {{Name : "node" , SubnetsAnnotation : "{\" default\" :\" 1.1.0.0/24\" , \" cluster_udn_red\" :\" 1.2.0.0/24\" , \" cluster_udn_blue\" :\" 1.3.0.0/24\" }" }},
484492 eips : []* testEIP {{Name : "eip" , EIPs : map [string ]string {"node" : "1.0.1.1" }}},
@@ -490,17 +498,19 @@ func TestController_reconcile(t *testing.T) {
490498 Annotations : map [string ]string {types .OvnRouteAdvertisementsKey : "ra/frrConfig/node" },
491499 NodeSelector : map [string ]string {"kubernetes.io/hostname" : "node" },
492500 Routers : []* testRouter {
493- {ASN : 1 , Prefixes : []string {"1.2.0.0/24" , "1.3.0.0/24" }, Imports : []string {"blue" , "red" }, Neighbors : []* testNeighbor {
494- {ASN : 1 , Address : "1.0.0.100" , Advertise : []string {"1.2.0.0/24" , "1.3.0.0/24" }, Receive : []string {"1.2.0.0/16/24" , "1.3.0.0/16/24" }},
501+ {ASN : 1 , Prefixes : []string {"1.2.0.0/24" , "1.3.0.0/24" , "1.4.0.0/16" , "1.5.0.0/16" }, Imports : []string {"black" , " blue" , "green " , "red" }, Neighbors : []* testNeighbor {
502+ {ASN : 1 , Address : "1.0.0.100" , Advertise : []string {"1.2.0.0/24" , "1.3.0.0/24" , "1.4.0.0/16" , "1.5.0.0/16" }, Receive : []string {"1.2.0.0/16/24" , "1.3.0.0/16/24" , "1.4.0.0/16" , "1.5.0.0/16 " }},
495503 }},
504+ {ASN : 1 , VRF : "black" , Imports : []string {"default" }},
496505 {ASN : 1 , VRF : "blue" , Imports : []string {"default" }},
506+ {ASN : 1 , VRF : "green" , Imports : []string {"default" }},
497507 {ASN : 1 , VRF : "red" , Imports : []string {"default" }},
498508 }},
499509 },
500- expectNADAnnotations : map [string ]map [string ]string {"red" : {types .OvnRouteAdvertisementsKey : "[\" ra\" ]" }, "blue" : {types .OvnRouteAdvertisementsKey : "[\" ra\" ]" }},
510+ expectNADAnnotations : map [string ]map [string ]string {"red" : {types .OvnRouteAdvertisementsKey : "[\" ra\" ]" }, "blue" : {types .OvnRouteAdvertisementsKey : "[\" ra\" ]" }, "green" : { types . OvnRouteAdvertisementsKey : "[ \" ra \" ]" }, "black" : { types . OvnRouteAdvertisementsKey : "[ \" ra \" ]" } },
501511 },
502512 {
503- name : "reconciles eip RouteAdvertisement for a single FRR config, node, non default network and non default target VRF" ,
513+ name : "(layer3) reconciles eip RouteAdvertisement for a single FRR config, node, non default network and non default target VRF" ,
504514 ra : & testRA {Name : "ra" , TargetVRF : "red" , AdvertiseEgressIPs : true , NetworkSelector : map [string ]string {"selected" : "true" }},
505515 frrConfigs : []* testFRRConfig {
506516 {
@@ -546,6 +556,53 @@ func TestController_reconcile(t *testing.T) {
546556 },
547557 expectNADAnnotations : map [string ]map [string ]string {"blue" : {types .OvnRouteAdvertisementsKey : "[\" ra\" ]" }},
548558 },
559+ {
560+ name : "(layer2) reconciles eip RouteAdvertisement for a single FRR config, node, non default networks and non default target VRF" ,
561+ ra : & testRA {Name : "ra" , TargetVRF : "green" , AdvertiseEgressIPs : true , NetworkSelector : map [string ]string {"selected" : "true" }},
562+ frrConfigs : []* testFRRConfig {
563+ {
564+ Name : "frrConfig" ,
565+ Namespace : frrNamespace ,
566+ Routers : []* testRouter {
567+ {ASN : 1 , VRF : "green" , Prefixes : []string {"1.4.0.0/16" }, Neighbors : []* testNeighbor {
568+ {ASN : 1 , Address : "1.0.0.100" },
569+ }},
570+ },
571+ },
572+ },
573+ nads : []* testNAD {
574+ {Name : "default" , Namespace : "ovn-kubernetes" , Network : "default" },
575+ {Name : "green" , Namespace : "green" , Network : util .GenerateCUDNNetworkName ("green" ), Topology : "layer2" , Subnet : "1.4.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
576+ {Name : "black" , Namespace : "black" , Network : util .GenerateCUDNNetworkName ("black" ), Topology : "layer2" , Subnet : "1.5.0.0/16" },
577+ },
578+ nodes : []* testNode {
579+ {Name : "node" , SubnetsAnnotation : "{\" default\" :\" 1.1.1.0/24\" " },
580+ },
581+ namespaces : []* testNamespace {
582+ {Name : "default" , Labels : map [string ]string {"selected" : "default" }},
583+ {Name : "green" , Labels : map [string ]string {"selected" : "green" }},
584+ {Name : "black" , Labels : map [string ]string {"selected" : "black" }},
585+ },
586+ eips : []* testEIP {
587+ {Name : "eip1" , EIPs : map [string ]string {"node" : "172.100.0.17" }, NamespaceSelector : map [string ]string {"selected" : "green" }}, // secondary interface EIP also advertised
588+ {Name : "eip2" , EIPs : map [string ]string {"node" : "1.0.1.4" }, NamespaceSelector : map [string ]string {"selected" : "black" }}, // namespace served by unselected network, ignored
589+ {Name : "eip3" , EIPs : map [string ]string {"node" : "1.0.1.5" }, NamespaceSelector : map [string ]string {"selected" : "green" }},
590+ },
591+ reconcile : "ra" ,
592+ expectAcceptedStatus : metav1 .ConditionTrue ,
593+ expectFRRConfigs : []* testFRRConfig {
594+ {
595+ Labels : map [string ]string {types .OvnRouteAdvertisementsKey : "ra" },
596+ Annotations : map [string ]string {types .OvnRouteAdvertisementsKey : "ra/frrConfig/node" },
597+ NodeSelector : map [string ]string {"kubernetes.io/hostname" : "node" },
598+ Routers : []* testRouter {
599+ {ASN : 1 , VRF : "green" , Prefixes : []string {"1.0.1.5/32" , "172.100.0.17/32" }, Neighbors : []* testNeighbor {
600+ {ASN : 1 , Address : "1.0.0.100" , Advertise : []string {"1.0.1.5/32" , "172.100.0.17/32" }},
601+ }},
602+ }},
603+ },
604+ expectNADAnnotations : map [string ]map [string ]string {"green" : {types .OvnRouteAdvertisementsKey : "[\" ra\" ]" }},
605+ },
549606 {
550607 name : "reconciles a RouteAdvertisement updating the generated FRRConfigurations if needed" ,
551608 ra : & testRA {Name : "ra" , AdvertisePods : true , AdvertiseEgressIPs : true , SelectsDefault : true },
@@ -620,8 +677,10 @@ func TestController_reconcile(t *testing.T) {
620677 },
621678 nads : []* testNAD {
622679 {Name : "default" , Namespace : "ovn-kubernetes" , Network : "default" , Labels : map [string ]string {"selected" : "true" }},
623- {Name : "red" , Namespace : "red" , Network : "cluster_udn_red" , Topology : "layer3" , Subnet : "1.2.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
624- {Name : "blue" , Namespace : "blue" , Network : "cluster_udn_blue" , Topology : "layer3" }, // not selected
680+ {Name : "red" , Namespace : "red" , Network : util .GenerateCUDNNetworkName ("red" ), Topology : "layer3" , Subnet : "1.2.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
681+ {Name : "blue" , Namespace : "blue" , Network : util .GenerateCUDNNetworkName ("blue" ), Topology : "layer3" }, // not selected
682+ {Name : "green" , Namespace : "green" , Network : util .GenerateCUDNNetworkName ("green" ), Topology : "layer2" , Subnet : "1.4.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
683+ {Name : "black" , Namespace : "black" , Network : util .GenerateCUDNNetworkName ("black" ), Topology : "layer2" }, // not selected
625684 },
626685 frrConfigs : []* testFRRConfig {
627686 {
@@ -636,6 +695,9 @@ func TestController_reconcile(t *testing.T) {
636695 {ASN : 1 , VRF : "red" , Prefixes : []string {"1.0.2.0/24" }, Neighbors : []* testNeighbor {
637696 {ASN : 1 , Address : "1.0.0.100" },
638697 }},
698+ {ASN : 1 , VRF : "green" , Prefixes : []string {"1.2.0.0/16" }, Neighbors : []* testNeighbor {
699+ {ASN : 1 , Address : "1.0.0.100" },
700+ }},
639701 },
640702 },
641703 {
@@ -658,6 +720,9 @@ func TestController_reconcile(t *testing.T) {
658720 {ASN : 1 , VRF : "red" , Prefixes : []string {"1.0.2.0/24" }, Neighbors : []* testNeighbor {
659721 {ASN : 1 , Address : "1.0.0.100" },
660722 }},
723+ {ASN : 1 , VRF : "green" , Prefixes : []string {"1.2.0.0/16" }, Neighbors : []* testNeighbor {
724+ {ASN : 1 , Address : "1.0.0.100" },
725+ }},
661726 },
662727 },
663728 { // not selected
@@ -688,6 +753,9 @@ func TestController_reconcile(t *testing.T) {
688753 {ASN : 1 , VRF : "red" , Prefixes : []string {"1.2.1.0/24" }, Neighbors : []* testNeighbor {
689754 {ASN : 1 , Address : "1.0.0.100" , Advertise : []string {"1.2.1.0/24" }, Receive : []string {"1.2.0.0/16/24" }},
690755 }},
756+ {ASN : 1 , VRF : "green" , Prefixes : []string {"1.4.0.0/16" }, Neighbors : []* testNeighbor {
757+ {ASN : 1 , Address : "1.0.0.100" , Advertise : []string {"1.4.0.0/16" }, Receive : []string {"1.4.0.0/16" }},
758+ }},
691759 },
692760 },
693761 {
@@ -708,6 +776,9 @@ func TestController_reconcile(t *testing.T) {
708776 {ASN : 1 , VRF : "red" , Prefixes : []string {"1.2.2.0/24" }, Neighbors : []* testNeighbor {
709777 {ASN : 1 , Address : "1.0.0.100" , Advertise : []string {"1.2.2.0/24" }, Receive : []string {"1.2.0.0/16/24" }},
710778 }},
779+ {ASN : 1 , VRF : "green" , Prefixes : []string {"1.4.0.0/16" }, Neighbors : []* testNeighbor {
780+ {ASN : 1 , Address : "1.0.0.100" , Advertise : []string {"1.4.0.0/16" }, Receive : []string {"1.4.0.0/16" }},
781+ }},
711782 },
712783 },
713784 },
@@ -722,15 +793,6 @@ func TestController_reconcile(t *testing.T) {
722793 reconcile : "ra" ,
723794 expectAcceptedStatus : metav1 .ConditionFalse ,
724795 },
725- {
726- name : "fails to reconcile an unsupported topology" ,
727- ra : & testRA {Name : "ra" , AdvertisePods : true , NetworkSelector : map [string ]string {"selected" : "true" }},
728- nads : []* testNAD {
729- {Name : "red" , Namespace : "red" , Network : "red" , Topology : "layer2" , Subnet : "1.2.0.0/16" , Labels : map [string ]string {"selected" : "true" }},
730- },
731- reconcile : "ra" ,
732- expectAcceptedStatus : metav1 .ConditionFalse ,
733- },
734796 {
735797 name : "fails to reconcile an non-cluster UDN" ,
736798 ra : & testRA {Name : "ra" , AdvertisePods : true , NetworkSelector : map [string ]string {"selected" : "true" }},
@@ -827,7 +889,7 @@ func TestController_reconcile(t *testing.T) {
827889 ra : & testRA {Name : "ra" , TargetVRF : "auto" , AdvertisePods : true , NetworkSelector : map [string ]string {"selected" : "true" }},
828890 nads : []* testNAD {
829891 {Name : "red" , Namespace : "red" , Network : "cluster_udn_red" , Topology : "layer3" , Labels : map [string ]string {"selected" : "true" }},
830- {Name : "blue" , Namespace : "blue" , Network : "cluster_udn_blue" , Topology : "layer3 " , Labels : map [string ]string {"selected" : "true" }},
892+ {Name : "blue" , Namespace : "blue" , Network : "cluster_udn_blue" , Topology : "layer2" , Subnet : "1.4.0.0/16 " , Labels : map [string ]string {"selected" : "true" }},
831893 },
832894 frrConfigs : []* testFRRConfig {
833895 {
@@ -840,7 +902,7 @@ func TestController_reconcile(t *testing.T) {
840902 },
841903 },
842904 },
843- nodes : []* testNode {{Name : "node" , SubnetsAnnotation : "{\" cluster_udn_red\" :\" 1.1.0.0/24\" , \" cluster_udn_blue \" : \" 1.2.0.0/24 \" }" }},
905+ nodes : []* testNode {{Name : "node" , SubnetsAnnotation : "{\" cluster_udn_red\" :\" 1.1.0.0/24\" }" }},
844906 reconcile : "ra" ,
845907 expectAcceptedStatus : metav1 .ConditionFalse ,
846908 },
@@ -1163,22 +1225,6 @@ func TestUpdates(t *testing.T) {
11631225 name : "does not reconcile a new unsupported (secondary) NAD" ,
11641226 newObject : & testNAD {Name : "net" , Namespace : "net" , Network : "net" , IsSecondary : true , Topology : "layer3" , Labels : map [string ]string {"select" : "2" }},
11651227 },
1166- {
1167- name : "does not reconcile a new unsupported (layer2 primary) NAD" ,
1168- newObject : & testNAD {Name : "net" , Namespace : "net" , Network : "net" , Topology : "layer2" , Subnet : "1.2.0.0/16" , Labels : map [string ]string {"select" : "2" }},
1169- },
1170- {
1171- name : "does not reconcile an updated unsupported NAD" ,
1172- oldObject : & testNAD {Name : "net" , Namespace : "net" , Network : "net" , Topology : "layer2" , Subnet : "1.2.0.0/16" , Labels : map [string ]string {"select" : "2" }},
1173- newObject : & testNAD {Name : "net" , Namespace : "net" , Network : "net" , Topology : "layer2" , Subnet : "1.2.0.0/16" , Labels : map [string ]string {"select" : "1" }},
1174- },
1175- {
1176- // TODO shouldn't happen but needs FIX in controller utility which
1177- // does not call filter predicate on deletes
1178- name : "reconciles all RAs on deleted unsupported NAD" ,
1179- oldObject : & testNAD {Name : "net" , Namespace : "net" , Network : "net" , Topology : "layer2" , Subnet : "1.2.0.0/16" , Labels : map [string ]string {"select" : "2" }},
1180- expectedReconcile : []string {"ra1" , "ra2" , "ra3" },
1181- },
11821228 {
11831229 name : "reconciles all RAs that advertise EIPs on new EIP with status" ,
11841230 newObject : & testEIP {Name : "eip" , EIPs : map [string ]string {"node" : "ip" }},
0 commit comments