Skip to content

Commit

Permalink
Implement the controller for API BGPPolicy
Browse files Browse the repository at this point in the history
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 `AddPeer` method of
  the BGP server instance.
- Get the BGP peers to be deleted and delete them by calling the `RemovePeer`
  method of the BGP server instance.
- Get the remaining BGP peers and calculate the updated BGP peers, then update
  them by calling the `UpdatePeer` 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]>
  • Loading branch information
hongliangl committed Jul 12, 2024
1 parent 5cee770 commit 3030553
Show file tree
Hide file tree
Showing 15 changed files with 2,776 additions and 10 deletions.
4 changes: 4 additions & 0 deletions build/charts/antrea/conf/antrea-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ featureGates:
# Enable NodeLatencyMonitor to monitor the latency between Nodes.
{{- include "featureGate" (dict "featureGates" .Values.featureGates "name" "NodeLatencyMonitor" "default" false) }}

# Allow users to initiate BGP process on selected Kubernetes Nodes and advertise Service IPs, Pod IPs and Egress IPs to
# remote BGP peers.
{{- include "featureGate" (dict "featureGates" .Values.featureGates "name" "BGPPolicy" "default" false) }}

# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: {{ .Values.ovs.bridgeName | quote }}
Expand Down
10 changes: 10 additions & 0 deletions build/charts/antrea/templates/agent/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ rules:
- apiGroups:
- crd.antrea.io
resources:
- bgppolicies
- externalippools
- ippools
- trafficcontrols
Expand Down Expand Up @@ -234,3 +235,12 @@ rules:
- create
- patch
- update
- apiGroups:
- ""
resources:
- secrets
resourceNames:
- antrea-bgp-passwords
verbs:
- get
- watch
18 changes: 16 additions & 2 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3807,6 +3807,10 @@ data:
# Enable NodeLatencyMonitor to monitor the latency between Nodes.
# NodeLatencyMonitor: false
# Allow users to initiate BGP process on selected Kubernetes Nodes and advertise Service IPs, Pod IPs and Egress IPs to
# remote BGP peers.
# BGPPolicy: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -4445,6 +4449,7 @@ rules:
- apiGroups:
- crd.antrea.io
resources:
- bgppolicies
- externalippools
- ippools
- trafficcontrols
Expand Down Expand Up @@ -4502,6 +4507,15 @@ rules:
- create
- patch
- update
- apiGroups:
- ""
resources:
- secrets
resourceNames:
- antrea-bgp-passwords
verbs:
- get
- watch
---
# Source: antrea/templates/antctl/clusterrole.yaml
kind: ClusterRole
Expand Down Expand Up @@ -5110,7 +5124,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: f976029accf54258d01ad907fe19b50ac671eee014cd8aea968c6a0bc7e8f95a
checksum/config: 32e079ffe409d512a54f34fa9312e54a5d4c9125aa9695fda915c83fe77e29b9
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -5348,7 +5362,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: f976029accf54258d01ad907fe19b50ac671eee014cd8aea968c6a0bc7e8f95a
checksum/config: 32e079ffe409d512a54f34fa9312e54a5d4c9125aa9695fda915c83fe77e29b9
labels:
app: antrea
component: antrea-controller
Expand Down
18 changes: 16 additions & 2 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3807,6 +3807,10 @@ data:
# Enable NodeLatencyMonitor to monitor the latency between Nodes.
# NodeLatencyMonitor: false
# Allow users to initiate BGP process on selected Kubernetes Nodes and advertise Service IPs, Pod IPs and Egress IPs to
# remote BGP peers.
# BGPPolicy: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -4445,6 +4449,7 @@ rules:
- apiGroups:
- crd.antrea.io
resources:
- bgppolicies
- externalippools
- ippools
- trafficcontrols
Expand Down Expand Up @@ -4502,6 +4507,15 @@ rules:
- create
- patch
- update
- apiGroups:
- ""
resources:
- secrets
resourceNames:
- antrea-bgp-passwords
verbs:
- get
- watch
---
# Source: antrea/templates/antctl/clusterrole.yaml
kind: ClusterRole
Expand Down Expand Up @@ -5110,7 +5124,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: f976029accf54258d01ad907fe19b50ac671eee014cd8aea968c6a0bc7e8f95a
checksum/config: 32e079ffe409d512a54f34fa9312e54a5d4c9125aa9695fda915c83fe77e29b9
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -5349,7 +5363,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: f976029accf54258d01ad907fe19b50ac671eee014cd8aea968c6a0bc7e8f95a
checksum/config: 32e079ffe409d512a54f34fa9312e54a5d4c9125aa9695fda915c83fe77e29b9
labels:
app: antrea
component: antrea-controller
Expand Down
18 changes: 16 additions & 2 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3807,6 +3807,10 @@ data:
# Enable NodeLatencyMonitor to monitor the latency between Nodes.
# NodeLatencyMonitor: false
# Allow users to initiate BGP process on selected Kubernetes Nodes and advertise Service IPs, Pod IPs and Egress IPs to
# remote BGP peers.
# BGPPolicy: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -4445,6 +4449,7 @@ rules:
- apiGroups:
- crd.antrea.io
resources:
- bgppolicies
- externalippools
- ippools
- trafficcontrols
Expand Down Expand Up @@ -4502,6 +4507,15 @@ rules:
- create
- patch
- update
- apiGroups:
- ""
resources:
- secrets
resourceNames:
- antrea-bgp-passwords
verbs:
- get
- watch
---
# Source: antrea/templates/antctl/clusterrole.yaml
kind: ClusterRole
Expand Down Expand Up @@ -5110,7 +5124,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 5299e6235e262daf606758cf900766470fcb8dd21a0d707a3ae284548bd8c2b2
checksum/config: 47194398fc7170ce91a41f7d0ee487c0adaf6725adc56aa08b299babc9ff6bc1
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -5346,7 +5360,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 5299e6235e262daf606758cf900766470fcb8dd21a0d707a3ae284548bd8c2b2
checksum/config: 47194398fc7170ce91a41f7d0ee487c0adaf6725adc56aa08b299babc9ff6bc1
labels:
app: antrea
component: antrea-controller
Expand Down
18 changes: 16 additions & 2 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3820,6 +3820,10 @@ data:
# Enable NodeLatencyMonitor to monitor the latency between Nodes.
# NodeLatencyMonitor: false
# Allow users to initiate BGP process on selected Kubernetes Nodes and advertise Service IPs, Pod IPs and Egress IPs to
# remote BGP peers.
# BGPPolicy: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -4458,6 +4462,7 @@ rules:
- apiGroups:
- crd.antrea.io
resources:
- bgppolicies
- externalippools
- ippools
- trafficcontrols
Expand Down Expand Up @@ -4515,6 +4520,15 @@ rules:
- create
- patch
- update
- apiGroups:
- ""
resources:
- secrets
resourceNames:
- antrea-bgp-passwords
verbs:
- get
- watch
---
# Source: antrea/templates/antctl/clusterrole.yaml
kind: ClusterRole
Expand Down Expand Up @@ -5123,7 +5137,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: ba93df141f512a1f8483114b5994444c7231b298e7e9133483ddc1f4210ec395
checksum/config: 7458c788aadb791e4450d83323a480c10aec1151dd41fce875ec3168526dc618
checksum/ipsec-secret: d0eb9c52d0cd4311b6d252a951126bf9bea27ec05590bed8a394f0f792dcb2a4
labels:
app: antrea
Expand Down Expand Up @@ -5405,7 +5419,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: ba93df141f512a1f8483114b5994444c7231b298e7e9133483ddc1f4210ec395
checksum/config: 7458c788aadb791e4450d83323a480c10aec1151dd41fce875ec3168526dc618
labels:
app: antrea
component: antrea-controller
Expand Down
18 changes: 16 additions & 2 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3807,6 +3807,10 @@ data:
# Enable NodeLatencyMonitor to monitor the latency between Nodes.
# NodeLatencyMonitor: false
# Allow users to initiate BGP process on selected Kubernetes Nodes and advertise Service IPs, Pod IPs and Egress IPs to
# remote BGP peers.
# BGPPolicy: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -4445,6 +4449,7 @@ rules:
- apiGroups:
- crd.antrea.io
resources:
- bgppolicies
- externalippools
- ippools
- trafficcontrols
Expand Down Expand Up @@ -4502,6 +4507,15 @@ rules:
- create
- patch
- update
- apiGroups:
- ""
resources:
- secrets
resourceNames:
- antrea-bgp-passwords
verbs:
- get
- watch
---
# Source: antrea/templates/antctl/clusterrole.yaml
kind: ClusterRole
Expand Down Expand Up @@ -5110,7 +5124,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: aca23e21519e0fc112647f23d3ce6f92a3dea0bc7ebf1c6d7a7eed2dbe80f0a3
checksum/config: b625d373051b7eb617a1e3e8f762c5b559fecf3569610b6c4494fb6bf3866e8b
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -5346,7 +5360,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: aca23e21519e0fc112647f23d3ce6f92a3dea0bc7ebf1c6d7a7eed2dbe80f0a3
checksum/config: b625d373051b7eb617a1e3e8f762c5b559fecf3569610b6c4494fb6bf3866e8b
labels:
app: antrea
component: antrea-controller
Expand Down
18 changes: 18 additions & 0 deletions cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"antrea.io/antrea/pkg/agent/cniserver"
"antrea.io/antrea/pkg/agent/cniserver/ipam"
"antrea.io/antrea/pkg/agent/config"
"antrea.io/antrea/pkg/agent/controller/bgp"
"antrea.io/antrea/pkg/agent/controller/egress"
"antrea.io/antrea/pkg/agent/controller/ipseccertificate"
"antrea.io/antrea/pkg/agent/controller/l7flowexporter"
Expand Down Expand Up @@ -743,6 +744,23 @@ func run(o *Options) error {
}
}

if features.DefaultFeatureGate.Enabled(features.BGPPolicy) {
bgpPolicyInformer := crdInformerFactory.Crd().V1alpha1().BGPPolicies()
bgpController, err := bgp.NewBGPPolicyController(ctx,
nodeInformer,
serviceInformer,
egressInformer,
bgpPolicyInformer,
endpointSliceInformer,
k8sClient,
nodeConfig,
networkConfig)
if err != nil {
return err
}
go bgpController.Run(stopCh)
}

if features.DefaultFeatureGate.Enabled(features.TrafficControl) {
tcController := trafficcontrol.NewTrafficControlController(ofClient,
ifaceStore,
Expand Down
7 changes: 7 additions & 0 deletions docs/feature-gates.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ edit the Agent configuration in the
| `EgressSeparateSubnet` | Agent | `false` | Alpha | v1.15 | N/A | N/A | No | |
| `NodeNetworkPolicy` | Agent | `false` | Alpha | v1.15 | N/A | N/A | Yes | |
| `L7FlowExporter` | Agent | `false` | Alpha | v1.15 | N/A | N/A | Yes | |
| `BGPPolicy` | Agent | `false` | Alpha | v2.1 | N/A | N/A | No | |

## Description and Requirements of Features

Expand Down Expand Up @@ -438,3 +439,9 @@ Refer to this [document](network-flow-visibility.md#l7-visibility) for more info
#### Requirements for this Feature

- Linux Nodes only.

### BGPPolicy

`BGPPolicy` allows users to initiate BGP process on selected Kubernetes Nodes and advertise Service IPs (e.g.,
ClusterIPs, ExternalIPs, LoadBalancerIPs), Pod IPs and Egress IPs to remote BGP peers, providing a flexible mechanism
for integrating Kubernetes clusters with external BGP-enabled networks.
Loading

0 comments on commit 3030553

Please sign in to comment.