Skip to content

Commit

Permalink
[NET-5688] APIGateway UI Topology Fixes (#19657) (#19764)
Browse files Browse the repository at this point in the history
* [NET-5688] APIGateway UI Topology Fixes (#19657)

* 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

* Remove BUSL license

* Fix import
  • Loading branch information
jm96441n authored Nov 29, 2023
1 parent 8874f1f commit 7cc019f
Show file tree
Hide file tree
Showing 59 changed files with 30,379 additions and 15,770 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 @@ -573,6 +573,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 @@ -615,6 +616,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 @@ -645,6 +650,9 @@ func (g *gatewayMeta) updateRouteBinding(route structs.BoundRoute) (bool, []stru
errors[ref] = fmt.Errorf("failed to bind route %s to gateway %s with listener '%s'", route.GetName(), g.Gateway.Name, ref.SectionName)
}
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 @@ -1049,6 +1057,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 @@ -212,6 +212,7 @@ func TestBoundAPIGatewayBindRoute(t *testing.T) {
Kind: structs.TerminatingGateway,
Name: "Gateway",
Listeners: []structs.BoundAPIGatewayListener{},
Services: make(structs.ServiceRouteReferences),
},
expectedDidBind: false,
},
Expand Down Expand Up @@ -479,6 +480,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -528,6 +530,7 @@ func TestBindRoutesToGateways(t *testing.T) {
Routes: []structs.ResourceReference{},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -623,6 +626,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
{
Name: "Gateway 2",
Expand All @@ -638,6 +642,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -715,6 +720,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -798,6 +804,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -887,6 +894,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1002,6 +1010,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
{
Name: "Gateway 2",
Expand All @@ -1021,6 +1030,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1104,6 +1114,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1210,6 +1221,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
{
Name: "Gateway 2",
Expand All @@ -1225,6 +1237,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1357,6 +1370,7 @@ func TestBindRoutesToGateways(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
expectedReferenceErrors: map[structs.ResourceReference]error{},
Expand Down Expand Up @@ -1994,6 +2008,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 @@ -2221,6 +2240,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 @@ -2370,6 +2399,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 @@ -2517,6 +2556,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 @@ -2677,6 +2720,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 @@ -2804,6 +2861,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 @@ -2893,6 +2951,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 @@ -3036,6 +3095,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 @@ -3209,6 +3276,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 @@ -3348,6 +3416,7 @@ func TestAPIGatewayController(t *testing.T) {
Listeners: []structs.BoundAPIGatewayListener{{
Name: "http-listener",
}},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3422,6 +3491,7 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3547,6 +3617,7 @@ func TestAPIGatewayController(t *testing.T) {
},
},
},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3646,6 +3717,7 @@ func TestAPIGatewayController(t *testing.T) {
{Name: "listener-1"},
{Name: "listener-2"},
},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3761,6 +3833,7 @@ func TestAPIGatewayController(t *testing.T) {
Name: "invalid-listener",
},
},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down Expand Up @@ -3849,6 +3922,7 @@ func TestAPIGatewayController(t *testing.T) {
EnterpriseMeta: *defaultMeta,
}},
}},
Services: make(structs.ServiceRouteReferences),
},
},
},
Expand Down
Loading

0 comments on commit 7cc019f

Please sign in to comment.