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 Route Type in output of "antctl get bgproutes" #6803

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions docs/antctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -803,25 +803,29 @@ For more information about route advertisement, please refer to [Advertisements]
# Get the list of all advertised bgp routes
$ antctl get bgproutes

ROUTE
10.96.10.10/32
192.168.77.100/32
fec0::10:96:10:10/128
fec0::192:168:77:100/128
ROUTE TYPE
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be more valuable IMO if in addition to the type, we had a reference to the K8s object

Copy link
Contributor

@rajnkamr rajnkamr Nov 14, 2024

Choose a reason for hiding this comment

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

Agree , as there might be multiple resources for a crd, In future, for ex, we could support multiple egress ips,
Something like below will be more explanatory and respectively for other resources

ROUTE                    TYPE                  K8s OBJECT REFERENCE
172.18.0.3/32            EgressIP           Egress: egress-1

10.244.1.0/24 NodeIPAMPodCIDR
10.96.0.1/32 LoadBalancerIP
172.18.0.3/32 EgressIP
fd00:10:244:1::/64 NodeIPAMPodCIDR
fec0::10:96:10:10/128 LoadBalancerIP
fec0::192:168:77:100/128 EgressIP

# Get the list of advertised IPv4 bgp routes
$ antctl get bgproutes --ipv4-only

ROUTE
10.96.10.10/32
192.168.77.100/32
ROUTE TYPE
10.244.1.0/24 NodeIPAMPodCIDR
10.96.0.1/32 LoadBalancerIP
172.18.0.3/32 EgressIP

# Get the list of advertised IPv6 bgp routes
$ antctl get bgproutes --ipv6-only

ROUTE
fec0::10:96:10:10/128
fec0::192:168:77:100/128
ROUTE TYPE
fd00:10:244:1::/64 NodeIPAMPodCIDR
fec0::10:96:10:10/128 LoadBalancerIP
fec0::192:168:77:100/128 EgressIP
```

### Upgrade existing objects of CRDs
Expand Down
5 changes: 3 additions & 2 deletions pkg/agent/apis/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,15 @@ func (r BGPPeerResponse) SortRows() bool {
// BGPRouteResponse describes the response struct of bgproutes command.
type BGPRouteResponse struct {
Route string `json:"route,omitempty"`
Type string `json:"type,omitempty"`
}

func (r BGPRouteResponse) GetTableHeader() []string {
return []string{"ROUTE"}
return []string{"ROUTE", "TYPE"}
}

func (r BGPRouteResponse) GetTableRow(_ int) []string {
return []string{r.Route}
return []string{r.Route, r.Type}
}

func (r BGPRouteResponse) SortRows() bool {
Expand Down
11 changes: 7 additions & 4 deletions pkg/agent/apiserver/handlers/bgproute/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ func HandleFunc(bq querier.AgentBGPPolicyInfoQuerier) http.HandlerFunc {
}

var bgpRoutesResp []apis.BGPRouteResponse
for _, bgpRoute := range bgpRoutes {
bgpRoutesResp = append(bgpRoutesResp, apis.BGPRouteResponse{
Route: bgpRoute,
})
for routeType := range bgpRoutes {
for _, bgpRoute := range bgpRoutes[routeType] {
bgpRoutesResp = append(bgpRoutesResp, apis.BGPRouteResponse{
Route: bgpRoute,
Type: string(routeType),
})
}
}

if err := json.NewEncoder(w).Encode(bgpRoutesResp); err != nil {
Expand Down
29 changes: 23 additions & 6 deletions pkg/agent/apiserver/handlers/bgproute/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,25 @@ func TestBGPRouteQuery(t *testing.T) {
name: "get all advertised routes",
expectedCalls: func(mockBGPServer *queriertest.MockAgentBGPPolicyInfoQuerier) {
mockBGPServer.EXPECT().GetBGPRoutes(ctx, true, true).Return(
[]string{"192.168.1.0/24", "192.168.2.0/24", "fec0::10:96:10:10/128"}, nil)
map[bgp.AdvertisedRouteType][]string{
bgp.ClusterIP: {"192.168.1.2/32"},
bgp.NodeIPAMPodCIDR: {"192.168.2.0/24"},
bgp.EgressIP: {"fec0::10:96:10:10/128"},
}, nil)
},
expectedStatus: http.StatusOK,
expectedResponse: []apis.BGPRouteResponse{
{
Route: "192.168.1.0/24",
Route: "192.168.1.2/32",
Type: "ClusterIP",
},
{
Route: "192.168.2.0/24",
Type: "NodeIPAMPodCIDR",
},
{
Route: "fec0::10:96:10:10/128",
Type: "EgressIP",
},
},
},
Expand All @@ -70,15 +77,20 @@ func TestBGPRouteQuery(t *testing.T) {
url: "?ipv4-only",
expectedCalls: func(mockBGPServer *queriertest.MockAgentBGPPolicyInfoQuerier) {
mockBGPServer.EXPECT().GetBGPRoutes(ctx, true, false).Return(
[]string{"192.168.1.0/24", "192.168.2.0/24"}, nil)
map[bgp.AdvertisedRouteType][]string{
bgp.ClusterIP: {"192.168.1.2/32"},
bgp.NodeIPAMPodCIDR: {"192.168.2.0/24"},
}, nil)
},
expectedStatus: http.StatusOK,
expectedResponse: []apis.BGPRouteResponse{
{
Route: "192.168.1.0/24",
Route: "192.168.1.2/32",
Type: "ClusterIP",
},
{
Route: "192.168.2.0/24",
Type: "NodeIPAMPodCIDR",
},
},
},
Expand All @@ -87,15 +99,20 @@ func TestBGPRouteQuery(t *testing.T) {
url: "?ipv6-only=",
expectedCalls: func(mockBGPServer *queriertest.MockAgentBGPPolicyInfoQuerier) {
mockBGPServer.EXPECT().GetBGPRoutes(ctx, false, true).Return(
[]string{"fec0::192:168:77:150/128", "fec0::10:10:0:10/128"}, nil)
map[bgp.AdvertisedRouteType][]string{
bgp.LoadBalancerIP: {"fec0::192:168:77:150/128"},
bgp.EgressIP: {"fec0::10:10:0:10/128"},
}, nil)
},
expectedStatus: http.StatusOK,
expectedResponse: []apis.BGPRouteResponse{
{
Route: "fec0::192:168:77:150/128",
Type: "LoadBalancerIP",
},
{
Route: "fec0::10:10:0:10/128",
Type: "EgressIP",
},
},
},
Expand Down Expand Up @@ -131,7 +148,7 @@ func TestBGPRouteQuery(t *testing.T) {
var received []apis.BGPRouteResponse
err = json.Unmarshal(recorder.Body.Bytes(), &received)
require.NoError(t, err)
assert.Equal(t, tt.expectedResponse, received)
assert.ElementsMatch(t, tt.expectedResponse, received)
}
})
}
Expand Down
Loading
Loading