Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the controller for API BGPPolicy #6203

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hongliangl
Copy link
Contributor

@hongliangl hongliangl commented Apr 9, 2024

This commit implements the controller of API BGPPolicy, designed to advertise
Service IPs, Egress IPs, and Pod IPs to BGP peers from selected Nodes.

According to the spec of BGPPolicy, the Node selector is used to select Nodes
to which a BGPPolicy is applied. Multiple BGPPolicies can be applied to the
same Node. However, only one BGPPolicy can be effective on a Node, with others
serving as alternatives. The first BGPPolicy applied to a Node will be the
effective one, and the latter ones will serve as alternatives. The effective one
may be changed in the following cases:

  • The current effective BGPPolicy is updated and not applied to the Node.
  • The current effective BGPPolicy is deleted.
  • The antrea-agent is rebooted, and an original alternative BGPPolicy is synced
    first and becomes effective.

The BGP server instance is only started for the effective BGPPolicy on a Node.
Currently, the BGP server instance is implemented by goBGP, and more BGP
server implementations might be added later. If the effective BGPPolicy is changed,
the corresponding BGP server instance will be terminated by calling the Stop()
method, and a new BGP server instance will be created and started by calling the
Start() method for the new effective BGPPolicy.

To start a BGP server instance, ASN, routerID, and listen port must be specified.
ASN and listen port are specified in the spec of the effective BGPPolicy. For
routerID, if the cluster is IPv4 only or dual stack, the IPv4 NodeIP is used as
the routerID; if the cluster is IPv6 only, the routerID must be specified in the
Node annotation antrea.io/bgp-route-id. Additionally, a new BGP server instance
should be created and started when any of ASN, routerID, or listen port changes.

The information of the BGP peers is specified in the effective BGPPolicy. The
unique identification of a BGP peer is the peer IP address.

To reconcile the latest BGP peers:

  • Get the BGP peers to be added and add them by calling the AddPeers method of
    the BGP server instance.
  • Get the BGP peers to be deleted and delete them by calling the RemovePeers
    method of the BGP server instance.
  • Get the remaining BGP peers and calculate the updated BGP peers, then update
    them by calling the UpdatePeers method of the BGP server instance.

The information of the IPs to be advertised can be calculated from the spec of
the effective BGPPolicy. Currently, we advertise the IPs and CIDRs to all the
BGP peers.

To reconcile the latest IPs to all BGP peers:

  • If the BGP server instance is newly created and started, advertise all the IPs
    by calling the AdvertiseRoutes method.
  • If the BGP server instance is not newly created and started:
    • Get the IPs/CIDRs to be added and advertise them by calling the
      AdvertiseRoutes method.
    • Get the IPs/CIDRs to be removed and withdraw them by calling the
      WithdrawRoutes method.

The feature is gated by the alpha BGPPolicy feature gate.

Depends on #6009

  • goBGP integration tests
  • e2e tests
  • unit tests
  • refine code comments
  • documents
  • goBGP logger

@hongliangl hongliangl added kind/feature Categorizes issue or PR as related to a new feature. action/release-note Indicates a PR that should be included in release notes. labels Apr 9, 2024
@rajnkamr rajnkamr added the area/transit/bgp Issues or PRs related to BGP support. label Apr 11, 2024
@hongliangl hongliangl added this to the Antrea v2.1 release milestone May 24, 2024
@hongliangl hongliangl force-pushed the 20240222-bgp-controller-v2 branch 2 times, most recently from f209e2a to 3063737 Compare May 30, 2024 10:40
@hongliangl hongliangl force-pushed the 20240222-bgp-controller-v2 branch 3 times, most recently from 57773d9 to c9b727a Compare June 6, 2024 12:25
@hongliangl hongliangl force-pushed the 20240222-bgp-controller-v2 branch 11 times, most recently from 095d7da to 5086b34 Compare June 19, 2024 07:23
@hongliangl hongliangl marked this pull request as ready for review June 19, 2024 07:26
@hongliangl hongliangl force-pushed the 20240222-bgp-controller-v2 branch 2 times, most recently from 3bab09b to 69c31a2 Compare June 20, 2024 05:55
@hongliangl hongliangl changed the title Add BGPPolicy controller Implement the controller for API BGPPolicy Jun 20, 2024
This commit implements the controller of API `BGPPolicy`, designed to advertise
Service IPs, Egress IPs, and Pod IPs to BGP peers from selected Nodes.

According to the spec of `BGPPolicy`, the Node selector is used to select Nodes
to which a `BGPPolicy` is applied. Multiple `BGPPolicies` can be applied to the
same Node. However, only one `BGPPolicy` can be effective on a Node, with others
serving as alternatives. The first `BGPPolicy` applied to a Node will be the
effective one, and the latter ones will serve as alternatives. The effective one
may be changed in the following cases:

- The current effective BGPPolicy is updated and not applied to the Node.
- The current effective BGPPolicy is deleted.
- The antrea-agent is rebooted, and an original alternative BGPPolicy is synced
  first and becomes effective.

The BGP server instance is only started for the effective BGPPolicy on a Node.
If the effective BGPPolicy is changed, the corresponding BGP server instance will
be terminated by calling the `Stop()` method, and a new BGP server instance will
be created and started by calling the `Start()` method for the new effective
BGPPolicy.

To start a BGP server instance, ASN, routerID, and listen port must be specified.
ASN and listen port are specified in the spec of the effective BGPPolicy. For
routerID, if the cluster is IPv4 only or dual stack, the IPv4 NodeIP is used as
the routerID; if the cluster is IPv6 only, the routerID must be specified in the
Node annotation `antrea.io/bgp-route-id`. Additionally, a new BGP server instance
should be created and started when any of ASN, routerID, or listen port changes.

The information of the BGP peers is specified in the effective BGPPolicy. The
unique identification of a BGP peer is the peer IP address.

To reconcile the latest BGP peers:

- Get the BGP peers to be added and add them by calling the `AddPeers` method of
  the BGP server instance.
- Get the BGP peers to be deleted and delete them by calling the `RemovePeers`
  method of the BGP server instance.
- Get the remaining BGP peers and calculate the updated BGP peers, then update
  them by calling the `UpdatePeers` method of the BGP server instance.

The information of the IPs to be advertised can be calculated from the spec of
the effective BGPPolicy. Currently, we advertise the IPs and CIDRs to all the
BGP peers.

To reconcile the latest IPs to all BGP peers:

- If the BGP server instance is newly created and started, advertise all the IPs
  by calling the `AdvertiseRoutes` method.
- If the BGP server instance is not newly created and started:
  - Get the IPs/CIDRs to be added and advertise them by calling the
    `AdvertiseRoutes` method.
  - Get the IPs/CIDRs to be removed and withdraw them by calling the
    `WithdrawRoutes` method.

The feature is gated by the alpha `BGPPolicy` feature gate.

Signed-off-by: Hongliang Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes. area/transit/bgp Issues or PRs related to BGP support. kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants