Skip to content

Commit

Permalink
[NET-5688] APIGateway UI Topology Fixes (#19657)
Browse files Browse the repository at this point in the history
* Update catalog and ui endpoints to show APIGateway in gateway service
topology view

* Added initial implementation for service view

* updated ui

* Fix topology view for gateways

* Adding tests for gw controller

* remove unused args

* Undo formatting changes

* Fix call sites for upstream/downstream gw changes

* Add config entry tests

* Fix function calls again

* Move from ServiceKey to ServiceName, cleanup from PR review

* Add additional check for length of services in bound apigateway for
IsSame comparison

* fix formatting for proto

* gofmt

* Add DeepCopy for retrieved BoundAPIGateway

* gofmt

* gofmt

* Rename function to be more consistent
  • Loading branch information
jm96441n authored Nov 28, 2023
1 parent fd1d97c commit a0240e3
Show file tree
Hide file tree
Showing 57 changed files with 14,085 additions and 11,799 deletions.
9 changes: 9 additions & 0 deletions agent/consul/gateways/controller_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ func getAllGatewayMeta(store *state.Store) ([]*gatewayMeta, error) {
meta := make([]*gatewayMeta, 0, len(boundGateways))
for _, b := range boundGateways {
bound := b.(*structs.BoundAPIGatewayConfigEntry)
bound = bound.DeepCopy()
for _, g := range gateways {
gateway := g.(*structs.APIGatewayConfigEntry)
if bound.IsInitializedForGateway(gateway) {
Expand Down Expand Up @@ -667,6 +668,10 @@ func (g *gatewayMeta) updateRouteBinding(route structs.BoundRoute) (bool, []stru
return nil
})

if g.BoundGateway.Services == nil {
g.BoundGateway.Services = make(structs.ServiceRouteReferences)
}

// now try and bind all of the route's current refs
for _, ref := range route.GetParents() {
if !g.shouldBindRoute(ref) {
Expand Down Expand Up @@ -708,6 +713,9 @@ func (g *gatewayMeta) updateRouteBinding(route structs.BoundRoute) (bool, []stru
}

if refDidBind {
for _, serviceName := range route.GetServiceNames() {
g.BoundGateway.Services.AddService(structs.NewServiceName(serviceName.Name, &serviceName.EnterpriseMeta), routeRef)
}
boundRefs = append(boundRefs, ref)
}
}
Expand Down Expand Up @@ -1138,6 +1146,7 @@ func removeRoute(route structs.ResourceReference, entries ...*gatewayMeta) []*ga
for _, entry := range entries {
if entry.unbindRoute(route) {
modified = append(modified, entry)
entry.BoundGateway.Services.RemoveRouteRef(route)
}
}

Expand Down
74 changes: 74 additions & 0 deletions agent/consul/gateways/controller_gateways_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func TestBoundAPIGatewayBindRoute(t *testing.T) {
Kind: structs.TerminatingGateway,
Name: "Gateway",
Listeners: []structs.BoundAPIGatewayListener{},
Services: make(structs.ServiceRouteReferences),
},
expectedDidBind: false,
},
Expand Down Expand Up @@ -484,6 +485,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -533,6 +535,7 @@ func TestBindRoutesToGateways(t *testing.T) {
Routes: []structs.ResourceReference{},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -628,6 +631,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
{
Name: "Gateway 2",
Expand All @@ -643,6 +647,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -720,6 +725,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -803,6 +809,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -892,6 +899,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1007,6 +1015,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
{
Name: "Gateway 2",
Expand All @@ -1026,6 +1035,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1109,6 +1119,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1215,6 +1226,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
{
Name: "Gateway 2",
Expand All @@ -1230,6 +1242,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1362,6 +1375,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1999,6 +2013,11 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},

Services: structs.ServiceRouteReferences{structs.NewServiceName("tcp-upstream", nil): []structs.ResourceReference{{
Kind: "tcp-route",
Name: "tcp-route",
}}},
},
&structs.APIGatewayConfigEntry{
Kind: structs.APIGateway,
Expand Down Expand Up @@ -2226,6 +2245,16 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},
Services: structs.ServiceRouteReferences{structs.NewServiceName("tcp-upstream", nil): []structs.ResourceReference{
{
Kind: "tcp-route",
Name: "tcp-route-one",
},
{
Kind: "tcp-route",
Name: "tcp-route-two",
},
}},
},
&structs.APIGatewayConfigEntry{
Kind: structs.APIGateway,
Expand Down Expand Up @@ -2375,6 +2404,16 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},
Services: structs.ServiceRouteReferences{structs.NewServiceName("http-upstream", nil): []structs.ResourceReference{
{
Kind: "http-route",
Name: "http-route-one",
},
{
Kind: "http-route",
Name: "http-route-two",
},
}},
},
&structs.APIGatewayConfigEntry{
Kind: structs.APIGateway,
Expand Down Expand Up @@ -2522,6 +2561,10 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},
Services: structs.ServiceRouteReferences{structs.NewServiceName("http-upstream", nil): []structs.ResourceReference{{
Kind: "http-route",
Name: "http-route",
}}},
},
&structs.APIGatewayConfigEntry{
Kind: structs.APIGateway,
Expand Down Expand Up @@ -2682,6 +2725,20 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},
Services: structs.ServiceRouteReferences{
structs.NewServiceName("http-upstream", nil): []structs.ResourceReference{
{
Kind: "http-route",
Name: "http-route",
},
},
structs.NewServiceName("tcp-upstream", nil): []structs.ResourceReference{
{
Kind: "tcp-route",
Name: "tcp-route",
},
},
},
},
&structs.APIGatewayConfigEntry{
Kind: structs.APIGateway,
Expand Down Expand Up @@ -2809,6 +2866,7 @@ func TestAPIGatewayController(t *testing.T) {
Name: "tcp-listener",
Routes: []structs.ResourceReference{},
}},
Services: make(structs.ServiceRouteReferences),
},
&structs.APIGatewayConfigEntry{
Kind: structs.APIGateway,
Expand Down Expand Up @@ -2898,6 +2956,7 @@ func TestAPIGatewayController(t *testing.T) {
Name: "tcp-listener",
Routes: []structs.ResourceReference{},
}},
Services: make(structs.ServiceRouteReferences),
},
&structs.APIGatewayConfigEntry{
Kind: structs.APIGateway,
Expand Down Expand Up @@ -3041,6 +3100,14 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},
Services: structs.ServiceRouteReferences{
structs.NewServiceName("http-upstream", nil): []structs.ResourceReference{
{
Kind: "http-route",
Name: "http-route",
},
},
},
},
&structs.APIGatewayConfigEntry{
Kind: structs.APIGateway,
Expand Down Expand Up @@ -3214,6 +3281,7 @@ func TestAPIGatewayController(t *testing.T) {
Name: "tcp-listener",
Routes: []structs.ResourceReference{},
}},
Services: make(structs.ServiceRouteReferences),
},
&structs.APIGatewayConfigEntry{
Kind: structs.APIGateway,
Expand Down Expand Up @@ -3353,6 +3421,7 @@ func TestAPIGatewayController(t *testing.T) {
Listeners: []structs.BoundAPIGatewayListener{{
Name: "http-listener",
}},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3427,6 +3496,7 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3552,6 +3622,7 @@ func TestAPIGatewayController(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3651,6 +3722,7 @@ func TestAPIGatewayController(t *testing.T) {
{Name: "listener-1"},
{Name: "listener-2"},
},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3766,6 +3838,7 @@ func TestAPIGatewayController(t *testing.T) {
Name: "invalid-listener",
},
},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3854,6 +3927,7 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down
Loading

0 comments on commit a0240e3

Please sign in to comment.