diff --git a/pkg/reconciler/layer2.go b/pkg/reconciler/layer2.go index 92502498..2f301b8c 100644 --- a/pkg/reconciler/layer2.go +++ b/pkg/reconciler/layer2.go @@ -142,6 +142,11 @@ func (r *reconcile) createL2(info *nl.Layer2Information, anycastTrackerInterface } func (r *reconcile) getDesired(l2vnis []networkv1alpha1.Layer2NetworkConfiguration) ([]nl.Layer2Information, error) { + availableVrfs, err := r.netlinkManager.ListL3() + if err != nil { + return nil, fmt.Errorf("error loading available VRFs: %w", err) + } + desired := []nl.Layer2Information{} for i := range l2vnis { spec := l2vnis[i].Spec @@ -157,6 +162,20 @@ func (r *reconcile) getDesired(l2vnis []networkv1alpha1.Layer2NetworkConfigurati return nil, fmt.Errorf("error parsing anycast gateways: %w", err) } + if len(spec.VRF) > 0 { + vrfAvailable := false + for _, info := range availableVrfs { + if info.Name == spec.VRF { + vrfAvailable = true + break + } + } + if !vrfAvailable { + r.Logger.Error(err, "VRF of Layer2 not found on node", "layer", l2vnis[i].ObjectMeta.Name, "vrf", spec.VRF) + continue + } + } + desired = append(desired, nl.Layer2Information{ VlanID: spec.ID, MTU: spec.MTU, diff --git a/pkg/reconciler/layer3.go b/pkg/reconciler/layer3.go index 7de9d15f..ec186ed2 100644 --- a/pkg/reconciler/layer3.go +++ b/pkg/reconciler/layer3.go @@ -109,8 +109,8 @@ func (r *reconcile) createVrfConfigMap(l3vnis []networkv1alpha1.VRFRouteConfigur vni = config.SkipVrfTemplateVni } else { err := fmt.Errorf("vrf not in vrf vni map") - r.Logger.Error(err, "VRF does not exist in VRF VNI config", "vrf", spec.VRF, "name", l3vnis[i].ObjectMeta.Name, "namespace", l3vnis[i].ObjectMeta.Namespace) - return nil, err + r.Logger.Error(err, "VRF does not exist in VRF VNI config, ignoring", "vrf", spec.VRF, "name", l3vnis[i].ObjectMeta.Name, "namespace", l3vnis[i].ObjectMeta.Namespace) + continue } cfg, err := createVrfConfig(vrfConfigMap, &spec, vni, rt)