Skip to content

Commit

Permalink
[external] Prefer external rotues to fabric-originated
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeymatov authored and Frostman committed Feb 8, 2024
1 parent 3379a2a commit 3fb33fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
23 changes: 23 additions & 0 deletions pkg/agent/dozer/bcm/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
PREFIX_LIST_VPC_LOOPBACK = "vpc-loopback-prefix"
NO_COMMUNITY = "no-community"
LST_GROUP_SPINELINK = "spinelink"
BGP_COMM_LIST_ALL_EXTERNALS = "all-externals"
)

func (p *broadcomProcessor) PlanDesiredState(ctx context.Context, agent *agentapi.Agent) (*dozer.Spec, error) {
Expand Down Expand Up @@ -560,7 +561,29 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error {

}

attachedExternals := map[string]bool{}
for _, attach := range agent.Spec.ExternalAttachments {
attachedExternals[attach.External] = true
}

spec.CommunityLists[BGP_COMM_LIST_ALL_EXTERNALS] = &dozer.SpecCommunityList{
Members: []string{},
}

spec.RouteMaps[ROUTE_MAP_BLOCK_EVPN_DEFAULT_REMOTE].Statements[fmt.Sprintf("%d", ROUTE_MAP_MAX_STATEMENT-10)] = &dozer.SpecRouteMapStatement{
Conditions: dozer.SpecRouteMapConditions{
MatchCommunityList: stringPtr(BGP_COMM_LIST_ALL_EXTERNALS),
},
SetLocalPreference: uint32Ptr(500),
Result: dozer.SpecRouteMapResultAccept,
}

for externalName, external := range agent.Spec.Externals {
spec.CommunityLists[BGP_COMM_LIST_ALL_EXTERNALS].Members = append(spec.CommunityLists[BGP_COMM_LIST_ALL_EXTERNALS].Members, external.InboundCommunity)
if !attachedExternals[externalName] {
continue
}

ipnsVrfName := ipnsVrfName(external.IPv4Namespace)

externalCommsCommList := ipNsExtCommsCommListName(external.IPv4Namespace)
Expand Down
12 changes: 6 additions & 6 deletions pkg/ctrl/agent/agent_ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,17 +365,17 @@ func (r *AgentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
}

externals := map[string]vpcapi.ExternalSpec{}
externalsToConfig := map[string]vpcapi.ExternalSpec{}
externalList := &vpcapi.ExternalList{}
err = r.List(ctx, externalList, client.InNamespace(sw.Namespace))
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "error listing externals")
}
for _, ext := range externalList.Items {
if !attachedExternals[ext.Name] {
continue
}

externals[ext.Name] = ext.Spec
if attachedExternals[ext.Name] {
externalsToConfig[ext.Name] = ext.Spec
}
}

externalPeerings := map[string]vpcapi.ExternalPeeringSpec{}
Expand All @@ -385,7 +385,7 @@ func (r *AgentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
return ctrl.Result{}, errors.Wrapf(err, "error listing external peerings")
}
for _, peering := range externalPeeringList.Items {
if _, exists := externals[peering.Spec.Permit.External.Name]; !exists {
if _, exists := externalsToConfig[peering.Spec.Permit.External.Name]; !exists {
continue
}

Expand Down Expand Up @@ -533,7 +533,7 @@ func (r *AgentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
}

externalsReq := map[string]bool{}
for name := range externals {
for name := range externalsToConfig {
externalsReq[name] = true
}

Expand Down

0 comments on commit 3fb33fe

Please sign in to comment.