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 "antctl get bgppolicy" agent command #6646

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

Atish-iaf
Copy link
Contributor

@Atish-iaf Atish-iaf commented Aug 30, 2024

Add antctl get bgppolicy agent command to get effective BGP policy applied on the Node.

For #6209

@Atish-iaf Atish-iaf force-pushed the support-bgp-in-antctl branch from b1b9ee0 to 187729c Compare August 30, 2024 11:42
@rajnkamr rajnkamr added this to the Antrea v2.2 release milestone Sep 5, 2024
@rajnkamr rajnkamr added area/transit/bgp Issues or PRs related to BGP support. action/release-note Indicates a PR that should be included in release notes. kind/documentation Categorizes issue or PR as related to a documentation. labels Sep 10, 2024
@Atish-iaf Atish-iaf force-pushed the support-bgp-in-antctl branch 3 times, most recently from 23b5852 to 47e4d33 Compare September 10, 2024 10:29
@Atish-iaf Atish-iaf marked this pull request as ready for review September 10, 2024 13:30
@Atish-iaf Atish-iaf changed the title Support BGP in antctl Add "antctl get bgppolicy" agent command Sep 10, 2024
pkg/agent/apiserver/handlers/bgppolicy/handler.go Outdated Show resolved Hide resolved
pkg/agent/apiserver/handlers/bgppolicy/handler.go Outdated Show resolved Hide resolved
pkg/agent/controller/bgp/controller.go Outdated Show resolved Hide resolved
pkg/agent/controller/bgp/controller.go Show resolved Hide resolved
bgpPolicyName, routerID, localASN, listenPort := bgpPolicyInfoQuerier.GetBGPPolicyInfo()
bgpPolicyResp := apis.BGPPolicyResponse{
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the client clearly identify when there is no effective BGPPolicy applied to the Node? In that scenario, antctl get bgppolicy should display an empty table, and not a table with one row of empty strings. So I want to make sure this is handled correctly by the current implementation?

pkg/agent/apiserver/handlers/bgppolicy/handler.go Outdated Show resolved Hide resolved
@Atish-iaf Atish-iaf force-pushed the support-bgp-in-antctl branch 2 times, most recently from 9fb88b7 to 6a521ec Compare September 13, 2024 19:12
docs/antctl.md Outdated Show resolved Hide resolved
pkg/agent/apiserver/handlers/bgppolicy/handler_test.go Outdated Show resolved Hide resolved
pkg/agent/apiserver/handlers/bgppolicy/handler_test.go Outdated Show resolved Hide resolved
pkg/agent/controller/bgp/controller_test.go Outdated Show resolved Hide resolved
pkg/agent/controller/bgp/controller_test.go Outdated Show resolved Hide resolved
Comment on lines 403 to 405
if reflect.Indirect(ref).IsZero() {
return "", nil
}
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 too specific to your use case IMO. A "zero" struct may not always mean "no object".
Honestly for this command, it would maybe make more sense to return a 404 Not Found in the API if there is no effective BGP policy.

Copy link
Contributor Author

@Atish-iaf Atish-iaf Sep 14, 2024

Choose a reason for hiding this comment

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

I think returning a 404 Not Found is not consistent as there are some other commands like antctl get addressgroup/appliedtogroup/netpol returning empty string as output without 404 when there is no resource. I think it is expected that a command should return zero exit code and run successfully when there is no resource. There is an e2e test for the same expectation.

func testAntctlAgentLocalAccess(t *testing.T, data *TestData) {
.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think your initial views were also similar #6646 (comment)

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 the comparison is not great
IMO, this command is more similar to antctl get addressgroup <name> than it is to antctl get addressgroup, because we are querying a specific object (the "effective" bgppolicy) and not a list of objects. And antctl get addressgroup <name> will return an error if there is no matching resource.

My original comment was more about antctl output formatting than it was about the API response.
We could in theory have the API return a 404, and the output be an empty table. But IMO, an error message like "there is no effective policy applied to the Node" with a non-zero error code is more appropriate. It is also easier to consume programmatically.

In any case, a 404 for the API response seems more appropriate than a "zero" struct.

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, thanks @antoninbas

@Atish-iaf Atish-iaf force-pushed the support-bgp-in-antctl branch from 6a521ec to fbd7874 Compare September 14, 2024 08:14
@Atish-iaf Atish-iaf force-pushed the support-bgp-in-antctl branch 4 times, most recently from 719d0d3 to ca18250 Compare September 17, 2024 05:26
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

one more minor comment, otherwise lgtm

pkg/agent/apiserver/handlers/bgppolicy/handler.go Outdated Show resolved Hide resolved
@@ -122,7 +122,7 @@ func testAntctlAgentLocalAccess(t *testing.T, data *TestData) {
cmd := strings.Join(args, " ")
t.Run(cmd, func(t *testing.T) {
stdout, stderr, err := runAntctl(podName, args, data)
if err != nil && !strings.HasSuffix(stderr, "not enabled\n") {
if err != nil && !(strings.HasSuffix(stderr, "not enabled\n") || strings.HasSuffix(stderr, "there is no effective bgp policy applied to the Node\n")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the change, but we need to find a better way to test this
The test is quite shallow anyway, as it doesn't really validate much, but anyway that is out-of-scope of the PR

Signed-off-by: Kumar Atish <kumar.atish@broadcom.com>
@Atish-iaf Atish-iaf force-pushed the support-bgp-in-antctl branch from ca18250 to 45a2cde Compare September 18, 2024 05:24
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

LGTM

@antoninbas antoninbas added area/component/antctl Issues or PRs releated to the command line interface component and removed kind/documentation Categorizes issue or PR as related to a documentation. labels Sep 18, 2024
@antoninbas
Copy link
Contributor

/test-all

@antoninbas antoninbas merged commit 84f60d2 into antrea-io:main Sep 18, 2024
57 of 62 checks passed
@Atish-iaf Atish-iaf mentioned this pull request Sep 19, 2024
4 tasks
@rajnkamr rajnkamr added the kind/documentation Categorizes issue or PR as related to a documentation. label Oct 21, 2024
hangyan pushed a commit to hangyan/antrea that referenced this pull request Oct 29, 2024
Add `antctl get bgppolicy` agent command to get effective BGP policy
applied on the Node.

The command is implemented using a new HTTP endpoint (`/bgppolicy`),
which will return a `404 Not Found` error if no BGPPolicy has been applied
on the Node.

For antrea-io#6209

Signed-off-by: Kumar Atish <kumar.atish@broadcom.com>
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/component/antctl Issues or PRs releated to the command line interface component area/transit/bgp Issues or PRs related to BGP support. kind/documentation Categorizes issue or PR as related to a documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants