99 . "github.com/onsi/ginkgo/v2"
1010 . "github.com/onsi/gomega"
1111
12+ apierrors "k8s.io/apimachinery/pkg/api/errors"
1213 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314 "k8s.io/apimachinery/pkg/util/intstr"
1415 "k8s.io/utils/ptr"
@@ -35,7 +36,7 @@ import (
3536//
3637// lo0 (Router-ID) — all 4 devices
3738// lo1 (primary VTEP) — leaf-1, leaf-2
38- // lo2 (anycast VTEP) — leaf-1, leaf-2
39+ // lo2 (anycast VTEP) — leaf-1, leaf-2 (only when spec.vtep.anycastVTEP is true)
3940// lo100 (anycast RP) — 1 Claim shared across spine-1, spine-2
4041var _ = Describe ("Fabric Controller" , func () {
4142 Context ("When reconciling with unnumbered underlay addressing" , func () {
@@ -211,6 +212,7 @@ var _ = Describe("Fabric Controller", func() {
211212 },
212213 VTEP : evpnv1alpha1.FabricVTEPSpec {
213214 DeviceSelector : metav1.LabelSelector {MatchLabels : map [string ]string {"role" : "leaf" }},
215+ AnycastVTEP : true ,
214216 },
215217 VNIPool : corev1alpha1.TypedLocalObjectReference {
216218 APIVersion : poolv1alpha1 .GroupVersion .String (),
@@ -570,6 +572,117 @@ var _ = Describe("Fabric Controller", func() {
570572 )))
571573 }).Should (Succeed ())
572574 })
575+
576+ It ("Should gate the lo2 anycast VTEP loopback on spec.vtep.anycastVTEP and clean it up on a transition to false" , func () {
577+ By ("Creating the Fabric with anycastVTEP disabled" )
578+ fabric := & evpnv1alpha1.Fabric {
579+ Name : "anycast-fabric" ,
580+ Namespace : metav1 .NamespaceDefault ,
581+ Spec : evpnv1alpha1.FabricSpec {
582+ DeviceSelector : metav1.LabelSelector {MatchLabels : map [string ]string {"topology.kubernetes.io/zone" : "test-zone" }},
583+ Loopbacks : evpnv1alpha1.FabricLoopbacksSpec {IPAddressPoolRef : corev1alpha1.LocalObjectReference {Name : loopbackPool .Name }},
584+ Underlay : evpnv1alpha1.FabricUnderlaySpec {
585+ Protocol : evpnv1alpha1 .UnderlayProtocolOSPF ,
586+ InterfaceSelector : metav1.LabelSelector {MatchLabels : map [string ]string {"role" : "fabric" }},
587+ Addressing : evpnv1alpha1.FabricUnderlayAddressingSpec {Unnumbered : true },
588+ },
589+ Overlay : evpnv1alpha1.FabricOverlaySpec {
590+ Protocol : evpnv1alpha1 .OverlayProtocolIBGP ,
591+ IBGP : & evpnv1alpha1.FabricIBGPSpec {
592+ ASNumber : intstr .FromInt (65000 ),
593+ RouteReflectors : []evpnv1alpha1.RouteReflectorGroup {{
594+ Name : "spines" ,
595+ DeviceSelector : metav1.LabelSelector {MatchLabels : map [string ]string {"role" : "spine" }},
596+ ClientDeviceSelector : metav1.LabelSelector {MatchLabels : map [string ]string {"role" : "leaf" }},
597+ }},
598+ },
599+ },
600+ BUM : evpnv1alpha1.FabricBUMSpec {
601+ Type : evpnv1alpha1 .BUMTypeMulticast ,
602+ PIM : & evpnv1alpha1.FabricPIMSpec {
603+ AnycastRendezvousPoints : []evpnv1alpha1.AnycastRendezvousPoint {{
604+ Name : "spine-rp" ,
605+ MulticastGroups : []corev1alpha1.IPPrefix {corev1alpha1 .MustParsePrefix ("224.0.0.0/4" )},
606+ DeviceSelector : metav1.LabelSelector {MatchLabels : map [string ]string {"role" : "spine" }},
607+ ClientDeviceSelector : metav1.LabelSelector {MatchLabels : map [string ]string {"role" : "leaf" }},
608+ }},
609+ },
610+ },
611+ VTEP : evpnv1alpha1.FabricVTEPSpec {
612+ DeviceSelector : metav1.LabelSelector {MatchLabels : map [string ]string {"role" : "leaf" }},
613+ AnycastVTEP : false ,
614+ },
615+ VNIPool : corev1alpha1.TypedLocalObjectReference {APIVersion : poolv1alpha1 .GroupVersion .String (), Kind : "IndexPool" , Name : indexPool .Name },
616+ },
617+ }
618+ Expect (k8sClient .Create (ctx , fabric )).To (Succeed ())
619+ DeferCleanup (func () {
620+ Expect (client .IgnoreNotFound (k8sClient .Delete (ctx , fabric ))).To (Succeed ())
621+ Expect (k8sClient .DeleteAllOf (ctx , & poolv1alpha1.Claim {}, client .InNamespace (metav1 .NamespaceDefault ))).To (Succeed ())
622+ Eventually (func (g Gomega ) {
623+ list := & poolv1alpha1.ClaimList {}
624+ g .Expect (k8sClient .List (ctx , list , client .InNamespace (metav1 .NamespaceDefault ))).To (Succeed ())
625+ g .Expect (list .Items ).To (BeEmpty ())
626+ }).Should (Succeed ())
627+ })
628+
629+ By ("Verifying lo1 is created but lo2 is not" )
630+ for _ , d := range []* corev1alpha1.Device {leaf1 , leaf2 } {
631+ Eventually (func (g Gomega ) {
632+ g .Expect (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-lo1" , Namespace : metav1 .NamespaceDefault }, & poolv1alpha1.Claim {})).To (Succeed ())
633+ }).Should (Succeed ())
634+ Consistently (func (g Gomega ) {
635+ g .Expect (apierrors .IsNotFound (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-lo2" , Namespace : metav1 .NamespaceDefault }, & poolv1alpha1.Claim {}))).To (BeTrue ())
636+ g .Expect (apierrors .IsNotFound (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-lo2" , Namespace : metav1 .NamespaceDefault }, & corev1alpha1.Interface {}))).To (BeTrue ())
637+ }, "1s" ).Should (Succeed ())
638+ }
639+
640+ By ("Verifying the NVE has no anycast source interface reference" )
641+ for _ , d := range []* corev1alpha1.Device {leaf1 , leaf2 } {
642+ Eventually (func (g Gomega ) {
643+ nve := & corev1alpha1.NetworkVirtualizationEdge {}
644+ g .Expect (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-nve" , Namespace : metav1 .NamespaceDefault }, nve )).To (Succeed ())
645+ g .Expect (nve .Spec .AnycastSourceInterfaceRef ).To (BeNil ())
646+ }).Should (Succeed ())
647+ }
648+
649+ By ("Enabling anycastVTEP and verifying lo2 Claim, Interface, and NVE reference appear" )
650+ Eventually (func (g Gomega ) {
651+ f := & evpnv1alpha1.Fabric {}
652+ g .Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (fabric ), f )).To (Succeed ())
653+ f .Spec .VTEP .AnycastVTEP = true
654+ g .Expect (k8sClient .Update (ctx , f )).To (Succeed ())
655+ }).Should (Succeed ())
656+
657+ for _ , d := range []* corev1alpha1.Device {leaf1 , leaf2 } {
658+ Eventually (func (g Gomega ) {
659+ g .Expect (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-lo2" , Namespace : metav1 .NamespaceDefault }, & poolv1alpha1.Claim {})).To (Succeed ())
660+ g .Expect (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-lo2" , Namespace : metav1 .NamespaceDefault }, & corev1alpha1.Interface {})).To (Succeed ())
661+ nve := & corev1alpha1.NetworkVirtualizationEdge {}
662+ g .Expect (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-nve" , Namespace : metav1 .NamespaceDefault }, nve )).To (Succeed ())
663+ g .Expect (nve .Spec .AnycastSourceInterfaceRef ).NotTo (BeNil ())
664+ g .Expect (nve .Spec .AnycastSourceInterfaceRef .Name ).To (Equal (fabric .Name + "-" + d .Name + "-lo2" ))
665+ }).Should (Succeed ())
666+ }
667+
668+ By ("Disabling anycastVTEP again and verifying lo2 Claim and Interface are cleaned up" )
669+ Eventually (func (g Gomega ) {
670+ f := & evpnv1alpha1.Fabric {}
671+ g .Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (fabric ), f )).To (Succeed ())
672+ f .Spec .VTEP .AnycastVTEP = false
673+ g .Expect (k8sClient .Update (ctx , f )).To (Succeed ())
674+ }).Should (Succeed ())
675+
676+ for _ , d := range []* corev1alpha1.Device {leaf1 , leaf2 } {
677+ Eventually (func (g Gomega ) {
678+ g .Expect (apierrors .IsNotFound (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-lo2" , Namespace : metav1 .NamespaceDefault }, & poolv1alpha1.Claim {}))).To (BeTrue ())
679+ g .Expect (apierrors .IsNotFound (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-lo2" , Namespace : metav1 .NamespaceDefault }, & corev1alpha1.Interface {}))).To (BeTrue ())
680+ nve := & corev1alpha1.NetworkVirtualizationEdge {}
681+ g .Expect (k8sClient .Get (ctx , client.ObjectKey {Name : fabric .Name + "-" + d .Name + "-nve" , Namespace : metav1 .NamespaceDefault }, nve )).To (Succeed ())
682+ g .Expect (nve .Spec .AnycastSourceInterfaceRef ).To (BeNil ())
683+ }).Should (Succeed ())
684+ }
685+ })
573686 })
574687
575688 Context ("When reconciling with numbered underlay addressing" , func () {
0 commit comments