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

[NET-5688] APIGateway UI Topology Fixes #19657

Merged
merged 19 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
8 changes: 8 additions & 0 deletions agent/consul/gateways/controller_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,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 +712,9 @@ func (g *gatewayMeta) updateRouteBinding(route structs.BoundRoute) (bool, []stru
}

if refDidBind {
for _, serviceName := range route.GetServiceNames() {
g.BoundGateway.Services.AddService(structs.NewServiceKey(serviceName.Name, &serviceName.EnterpriseMeta), routeRef)
}
boundRefs = append(boundRefs, ref)
}
}
Expand Down Expand Up @@ -1138,6 +1145,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.NewServiceKey("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.NewServiceKey("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.NewServiceKey("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.NewServiceKey("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.NewServiceKey("http-upstream", nil): []structs.ResourceReference{
{
Kind: "http-route",
Name: "http-route",
},
},
structs.NewServiceKey("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.NewServiceKey("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
Loading