bgpv2: Support overlapping selector matches on CiliumBGPAdvertisement#36414
Merged
qmonnet merged 1 commit intocilium:mainfrom Jan 2, 2025
Merged
bgpv2: Support overlapping selector matches on CiliumBGPAdvertisement#36414qmonnet merged 1 commit intocilium:mainfrom
qmonnet merged 1 commit intocilium:mainfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure your pull request adheres to the following guidelines:
description and a
Fixes: #XXXline if the commit addresses a particularGitHub issue.
Fixes: <commit-id>tag, thenplease add the commit author[s] as reviewer[s] to this issue.
bgpv2: Support overlapping selector matches on CiliumBGPAdvertisement
Overview
When configuring CiliumBGPAdvertisement with overlapping selector matches prior to this PR, the last sequential match was used, and previous matches were ignored.
This PR modifies Cilium to support overlapping matches. Overlaps are handled as additive operations for attributes that can be unioned (standard and large communities). When differing Local Preference values are set, the higher value is selected. This is in line with RFC 4271 which states "The higher degree of preference MUST be preferred."
The purpose of this change is to offer more flexibility for administrators of Cilium using the BGP Control Plane. The flexibility added allows the administrator to configure any combination of BGP communities for Service announcements without explicitly defining every possible combination in advance on their
CiliumBGPAdvertisement.Prior to this change, an administrator would have been required to define a Kubernetes label for every possible combination of BGP communities and then define on their
CiliumBGPAdvertisementin theadvertisementssection a label selector-based match for each unique combination of communities. In more complex networks, this poses a significant administrative burden and introduces the risk of configuration drift.Instead, the administrator now needs to define one label per BGP community that they wish to set. On their
CiliumBGPAdvertisement, theadvertisementssection simply needs a label selector match for each individual community. If twoadvertisementsmatch, the BGP communities defined on each entry will be applied to the corresponding advertisement. TheCiliumBGPAdvertisementno longer needs to be aware of the various combinations of communities that could be desired. Instead, combinations of communities are set by simply labeling the respective Kubernetes Service with the respective labels.The use-case above is further described in this GitHub Issue.
Fixes: #35721
Description
service.go:The focus of this PR are the changes made to
pkg/bgpv1/manager/reconcilerv2/service.goongetDesiredSvcRoutePolicies(). Prior to this change, each iteration simply updated the map nameddesiredSvcRoutePolicieswithout checking for an existing value.policies.go:This PR adds the function
MergeRoutePolicies()topolicies.go, which implements the merge operation. The reconciliation process sequentially passes each overlapping match through that. The final policy applied represents the merge of all which matched.The merge operation is defined as:
types/bgp.go:In this file, a change was made to add a
String()method for the typeRoutePolicyConditions. As the merge operation uses a map to track each unique set ofRoutePolicyConditions, the newString()method provides a simple hashable key.Docs
This PR updates the BGPv2 Control Plane Docs to describe the change in behavior, shown below:
Testing
Unit Tests
service_test.go:Unit tests for
ClusterIP,External, andLoadBalancerService advertisements were updated to each add a new test that configures overlapping advertisements. The overlapping advertisement tests each configure three advertisements, compared to all other tests which configure one. The advertisements configured set the following sets of attributes:The first and second each set unique communities for
StandardandLarge. The third first sets the same communities as the second, then adds a uniqueStandardandLargecommunity. The first and latter two set differentLocalPreferencevalues.policies_test.go:Tests were added here to cover expected and edge cases for
MergeRoutePolicies().Manual Testing
The lab from https://github.com/cilium/cilium/tree/main/contrib/containerlab/bgpv2/service was used to manually test this change. Using the
Makefilefrom that directory, I brought up a Kind cluster running Cilium with an instance of FRR. I commented out the lines that applied configuration to Cilium.Instead, I applied the following
yamlfile usingkubectl:Inspecting FRR
On FRR, shown below, I saw the superset of all communities defined above set on the Service announcement:
Coverage
Using the
uncovercommand line, coverage forpkg/bgpv1/manager/reconcilerv2under this PR is now:On
mainas of writing, it was:Fixes: #35721