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

Add BGP confederation support in BGPPolicy #6927

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

Conversation

hongliangl
Copy link
Contributor

@hongliangl hongliangl commented Jan 15, 2025

For #6567

Done: add some text about ASN to documentation.

Depends on #6905

@hongliangl hongliangl added action/release-note Indicates a PR that should be included in release notes. area/transit/bgp Issues or PRs related to BGP support. labels Jan 15, 2025
@hongliangl hongliangl added this to the Antrea v2.3 release milestone Jan 15, 2025
@hongliangl hongliangl force-pushed the 20241205-bgp-confederation-controller branch from 5e8cee4 to c1233b6 Compare January 21, 2025 13:14
@hongliangl hongliangl marked this pull request as ready for review January 21, 2025 13:14
@hongliangl hongliangl force-pushed the 20241205-bgp-confederation-controller branch from c1233b6 to 8bd9ee8 Compare January 24, 2025 04:16
docs/bgp-policy.md Outdated Show resolved Hide resolved
Comment on lines 110 to 113
### Confederation

The `Confederation` field specifies that the BGP process operates within a confederation identified by ASN `65000`,
with other member ASNs `64513` and `64514`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only field for which the description refers to specific values used in the example, so that's inconsistent. I would recommend just having a generic description here, and adding a link to the more comprehensive confederation example which comes later in the document.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

docs/bgp-policy.md Outdated Show resolved Hide resolved
docs/bgp-policy.md Outdated Show resolved Hide resolved
pkg/agent/controller/bgp/controller.go Outdated Show resolved Hide resolved
pkg/agent/controller/bgp/controller.go Outdated Show resolved Hide resolved
Comment on lines 347 to 348
return !(a == nil && b == nil) &&
(a == nil || b == nil || a.identifier != b.identifier || !a.peers.Equal(b.peers))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems incorrect to me. If a and b are both nil, the function will return false because of the negation (!(a == nil && b == nil). Am I missing something, and if not, should this be caught by unit tests? Could you double check?

I would have expected something like this:

return (a == nil && b == nil) || (a != nil && b != nil && a.identifier == b.identifier && a.peers.Equal(b.peers))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code you provided improves readability within the function, but its logic represents confederationConfigNotChanged, not the current one confederationConfigChanged, if I understand correctly.

Currently, the code implements the opposite logic in confederationConfigChanged, which is less readable. The logic for confederationConfigChanged is:

!(a == nil && b == nil) && (a == nil || b == nil || a.identifier != b.identifier || !a.peers.Equal(b.peers)).

If we negate it, the result simplifies to:

  • !!(a == nil && b == nil) && (a == nil || b == nil || a.identifier != b.identifier || !a.peers.Equal(b.peers))
  • (a == nil && b == nil) || !(a == nil || b == nil || a.identifier != b.identifier || !a.peers.Equal(b.peers))
  • (a == nil && b == nil) || (a != nil && b != nil && a.identifier == b.identifier && a.peers.Equal(b.peers))

It is the same as the example you provided.

@hongliangl hongliangl force-pushed the 20241205-bgp-confederation-controller branch from 8bd9ee8 to 8c3d330 Compare February 6, 2025 09:48
@hongliangl hongliangl requested a review from antoninbas February 6, 2025 09:50
}
}

func confederationConfigNotChanged(a, b *confederationConfig) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename to confederationConfigEqual now that you have inverted the logic?

@@ -1890,7 +2106,8 @@ func generateBGPPolicyState(bgpPolicyName string,
localASN int32,
routerID string,
bgpRoutes []bgp.Route,
peerConfigs []bgp.PeerConfig) *bgpPolicyState {
peerConfigs []bgp.PeerConfig,
patchFns ...func(*bgpPolicyState)) *bgpPolicyState {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's weird to introduce this patching mechanism but only use it for configuring the confederation.

I think you should either:

  1. use a *confederationConfig parameter (nil is used if there is no confederation), or
  2. use "patch" functions for everything

An example of solution 2:

generateBGPPolicyState("foo", x, y, z, withRoutes(route1, route2), withPeers(peer1, peer2, peer3))
generateBGPPolicyState("bar", x, y, z, withRoutes(route1, route2), withPeers(peer1), withConfederation(c))

Comment on lines +157 to +158
defer data.crdClient.CrdV1alpha1().BGPPolicies().Delete(context.TODO(), bgpPolicyName, metav1.DeleteOptions{})
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these lines should be swapped?

NodeSelector: metav1.LabelSelector{
MatchLabels: map[string]string{},
t.Run("One BGPPolicy applied to all Nodes", func(t *testing.T) {
const bgpPolicyName = "test-policy-alfa"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean "alpha" :P

updatedBGPPolicy.Spec.Advertisements.Pod = nil
_, err = data.crdClient.CrdV1alpha1().BGPPolicies().Update(context.TODO(), updatedBGPPolicy, metav1.UpdateOptions{})
require.NoError(t, err)
t.Run("Multiple BGPPolies applied to different Nodes within a confederation", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: s/BGPPolies/BGPPolicies

Comment on lines +269 to +277
t.Log("Verify the connectivity of the installed routes on remote FRR route")
ipsToConnect := []string{podIP, clusterIP}
for _, ip := range ipsToConnect {
cmd := fmt.Sprintf("/usr/bin/wget -O - http://%s:8080/hostname -T 5", ip)
rc, stdout, _, err := exec.RunDockerExecCommand(externalInfo.externalFRRCID, cmd, "/", nil, "")
require.NoError(t, err)
require.Equal(t, 0, rc)
require.Equal(t, podName, stdout)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is repeated multiple times, could you define a helper function - ideally inside the test function

Comment on lines +284 to +286
defer func() {
data.updateServiceInternalTrafficPolicy("agnhost-svc", false)
}()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer data.updateServiceInternalTrafficPolicy("agnhost-svc", false)

Comment on lines +256 to +257
defer data.crdClient.CrdV1alpha1().BGPPolicies().Delete(context.TODO(), bgpPolicyName, metav1.DeleteOptions{})
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines +213 to +214
const confederationIdentifier = int32(60000)
const updatedConfederationIdentifier = int32(60001)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these constants don't really need to be "typed"

t.Log("Create a test BGPPolicy selecting all Nodes as well as advertising ClusterIPs and Pod CIDRs")
const confederationIdentifier = int32(60000)
const updatedConfederationIdentifier = int32(60001)
asnStart := int32(61000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on usage, I am not sure why you use a variable here while you use constants for confederation identifiers.

- `identifier`: Specifies the ASN of the confederation, serving as its identifier.
- `memberASNs`: Specifies the ASNs of other members that are part of the confederation.

See example [BGP Confederation].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe update the [Confederation] to [Advertise Pod IPs through BGP Confederation] to avoid the internal link with number like '(#confederation-1)' in TOC.

apiVersion: crd.antrea.io/v1alpha1
kind: BGPPolicy
metadata:
name: example-bgp-policy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: example-bgp-policy
name: example-bgp-policy-with-confederation

notExpectedRoutes := []FRRRoute{{Prefix: clusterIP + "/32", Nexthops: getAllNodeIPs()}}
checkFRRRouterBGPRoutes(t, expectedRoutes, notExpectedRoutes)

t.Log("verify the connectivity of the installed routes on remote FRR route")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Log("verify the connectivity of the installed routes on remote FRR route")
t.Log("verify the connectivity of the installed routes on the remote FRR router")

require.NoError(t, err)
}

t.Log("Get routes installed on remote FRR router and verify them")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Log("Get routes installed on remote FRR router and verify them")
t.Log("Get routes installed on the remote FRR router and verify them")

expectedRoutes = []FRRRoute{{Prefix: clusterIP + "/32", Nexthops: []string{nodeIPv4(0)}}}
notExpectedRoutes := []FRRRoute{{Prefix: clusterIP + "/32", Nexthops: getAllNodeIPs()}}
checkFRRRouterBGPRoutes(t, expectedRoutes, notExpectedRoutes)
t.Log("Get the routes installed on remote FRR router and verify them")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}

for _, bgpPolicy := range bgpPolicies {
t.Log("Update the test BGPPolicy with a new confederation identifier and removing Pod CIDR advertisement")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Log("Update the test BGPPolicy with a new confederation identifier and removing Pod CIDR advertisement")
t.Log("Update the test BGPPolicy %s with a new confederation identifier and removing Pod CIDR advertisement", bgpPolicy.Name)

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants