Skip to content

Commit 33b9ef5

Browse files
committed
Gate anycast VTEP loopback behind Fabric feature flag
Add an optional anycastVTEP field to FabricVTEPSpec (default false) that controls whether the anycast VTEP loopback (lo2) is allocated on each VTEP device. When enabled, the Fabric allocates the lo2 Claim and Interface and references it as the NVE anycast source. When disabled, no lo2 is allocated and the NVE anycast source reference is cleared. Flipping the flag to false also cleans up any lo2 Claim and Interface the Fabric previously created. Deleting the Claim is safe: it is a disposable, deterministically-named request object, and IP stability across a re-enable is handled at the allocation layer (pool reclaim policy Retain and/or pre-provisioned allow-binding allocations survive Claim deletion and re-bind on recreation). Anycast VTEP is a vPC multi-homing construct: vPC peers share a secondary VTEP address so remote VTEPs treat the pair as one logical VTEP. ESI multi-homing uses per-switch VTEP identity instead and does not need it, so making lo2 opt-in avoids provisioning an unused shared loopback on ESI-based fabrics. Signed-off-by: Sebastian Wagner <sebastian.wagner02@sap.com>
1 parent f5ee53e commit 33b9ef5

6 files changed

Lines changed: 182 additions & 5 deletions

File tree

‎api/evpn/v1alpha1/fabric_types.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ type FabricVTEPSpec struct {
236236
// +required
237237
DeviceSelector metav1.LabelSelector `json:"deviceSelector"`
238238

239+
// anycastVTEP enables allocation of an anycast VTEP loopback (lo2) on each
240+
// VTEP device. Disabling it removes the lo2 Claim and Interface the fabric
241+
// previously created; the underlying IP is released or retained per the
242+
// pool's reclaim policy.
243+
// +optional
244+
// +kubebuilder:default=false
245+
AnycastVTEP bool `json:"anycastVTEP,omitempty"`
246+
239247
// anycastGateway configures the anycast gateway shared across all VTEP devices.
240248
// +optional
241249
AnycastGateway *FabricAnycastGatewaySpec `json:"anycastGateway,omitempty"`

‎charts/network-operator/templates/crd/fabrics.evpn.networking.metal.ironcore.dev.yaml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/crd/bases/evpn.networking.metal.ironcore.dev_fabrics.yaml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/api-reference/index.md‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/controller/evpn/fabric_controller.go‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ func (r *FabricReconciler) reconcileSystemLoopbacks(ctx context.Context, fabric
406406
return ctrl.Result{}, nil
407407
}
408408

409-
// reconcileVTEPLoopbacks ensures lo1 (primary VTEP) and lo2 (anycast VTEP) exist on VTEP devices.
409+
// reconcileVTEPLoopbacks ensures lo1 (primary VTEP) on VTEP devices, plus lo2 (anycast
410+
// VTEP) when spec.vtep.anycastVTEP is enabled. When disabled, any previously created lo2
411+
// Interface and Claim are removed; deleting the Claim is safe because IP stability across
412+
// a re-enable is handled at the allocation layer (reclaim policy / allow-binding).
410413
func (r *FabricReconciler) reconcileVTEPLoopbacks(ctx context.Context, fabric *evpnv1alpha1.Fabric, state *ReconcileState) (ctrl.Result, error) {
411414
selector, err := metav1.LabelSelectorAsSelector(&fabric.Spec.VTEP.DeviceSelector)
412415
if err != nil {
@@ -417,8 +420,12 @@ func (r *FabricReconciler) reconcileVTEPLoopbacks(ctx context.Context, fabric *e
417420
return ctrl.Result{}, fmt.Errorf("listing VTEP devices: %w", err)
418421
}
419422
slices.SortFunc(devices.Items, func(a, b v1alpha1.Device) int { return cmp.Compare(a.Name, b.Name) })
423+
ids := []int{LoopbackVTEP}
424+
if fabric.Spec.VTEP.AnycastVTEP {
425+
ids = append(ids, LoopbackVTEPAnycast)
426+
}
420427
for i := range devices.Items {
421-
for _, id := range []int{LoopbackVTEP, LoopbackVTEPAnycast} {
428+
for _, id := range ids {
422429
claimName := fmt.Sprintf("%s-%s-lo%d", fabric.Name, devices.Items[i].Name, id)
423430
claim, err := r.reconcileLoopbackClaim(ctx, fabric, claimName)
424431
if err != nil {
@@ -432,10 +439,37 @@ func (r *FabricReconciler) reconcileVTEPLoopbacks(ctx context.Context, fabric *e
432439
state.loopbacks[devices.Items[i].Name] = append(state.loopbacks[devices.Items[i].Name], intf)
433440
}
434441
}
442+
if !fabric.Spec.VTEP.AnycastVTEP {
443+
if err := r.deleteVTEPAnycastLoopback(ctx, fabric, devices.Items[i].Name); err != nil {
444+
return ctrl.Result{}, err
445+
}
446+
}
435447
}
436448
return ctrl.Result{}, nil
437449
}
438450

451+
// deleteVTEPAnycastLoopback removes the lo2 Interface and Claim for a VTEP device.
452+
func (r *FabricReconciler) deleteVTEPAnycastLoopback(ctx context.Context, fabric *evpnv1alpha1.Fabric, deviceName string) error {
453+
name := fmt.Sprintf("%s-%s-lo%d", fabric.Name, deviceName, LoopbackVTEPAnycast)
454+
intf := &v1alpha1.Interface{Name: name, Namespace: fabric.Namespace}
455+
if err := r.Delete(ctx, intf); err != nil {
456+
if !apierrors.IsNotFound(err) {
457+
return fmt.Errorf("deleting anycast VTEP interface %s: %w", name, err)
458+
}
459+
} else {
460+
r.Recorder.Eventf(fabric, nil, "Normal", "InterfaceDeleted", "Reconcile", "Deleted anycast VTEP interface %s", name)
461+
}
462+
claim := &poolv1alpha1.Claim{Name: name, Namespace: fabric.Namespace}
463+
if err := r.Delete(ctx, claim); err != nil {
464+
if !apierrors.IsNotFound(err) {
465+
return fmt.Errorf("deleting anycast VTEP claim %s: %w", name, err)
466+
}
467+
} else {
468+
r.Recorder.Eventf(fabric, nil, "Normal", "ClaimDeleted", "Reconcile", "Deleted anycast VTEP claim %s", name)
469+
}
470+
return nil
471+
}
472+
439473
// reconcileAnycastRPLoopbacks ensures lo100 (PIM anycast RP) exists on RP devices.
440474
// One claim is allocated per AnycastRendezvousPoint group; all RP devices in the group
441475
// share that single address.
@@ -1282,7 +1316,8 @@ func (r *FabricReconciler) reconcilePIM(ctx context.Context, deviceName string,
12821316
}
12831317

12841318
// reconcileVTEPNVE creates one NetworkVirtualizationEdge resource per VTEP device.
1285-
// The NVE references lo1 (primary VTEP) as source and lo2 (anycast VTEP) as anycast source.
1319+
// The NVE references lo1 (primary VTEP) as source, and lo2 (anycast VTEP) as anycast
1320+
// source when spec.vtep.anycastVTEP is enabled.
12861321
func (r *FabricReconciler) reconcileVTEPNVE(ctx context.Context, fabric *evpnv1alpha1.Fabric, state *ReconcileState) (ctrl.Result, error) {
12871322
selector, err := metav1.LabelSelectorAsSelector(&fabric.Spec.VTEP.DeviceSelector)
12881323
if err != nil {
@@ -1332,7 +1367,11 @@ func (r *FabricReconciler) reconcileNVE(ctx context.Context, device *v1alpha1.De
13321367
nve.Spec.HostReachability = v1alpha1.HostReachabilityTypeBGP
13331368
nve.Spec.SuppressARP = true
13341369
nve.Spec.SourceInterfaceRef = v1alpha1.LocalObjectReference{Name: lo1Name}
1335-
nve.Spec.AnycastSourceInterfaceRef = &v1alpha1.LocalObjectReference{Name: lo2Name}
1370+
if fabric.Spec.VTEP.AnycastVTEP {
1371+
nve.Spec.AnycastSourceInterfaceRef = &v1alpha1.LocalObjectReference{Name: lo2Name}
1372+
} else {
1373+
nve.Spec.AnycastSourceInterfaceRef = nil
1374+
}
13361375
if fabric.Spec.VTEP.AnycastGateway != nil {
13371376
nve.Spec.AnycastGateway = &v1alpha1.AnycastGateway{
13381377
VirtualMAC: fabric.Spec.VTEP.AnycastGateway.VirtualMAC,

‎internal/controller/evpn/fabric_controller_test.go‎

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
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
4041
var _ = 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

Comments
 (0)