mesh: prevent writing a ComputedRoutes with no ported configs (#18833)

This commit is contained in:
R.B. Boyer 2023-09-15 15:13:01 -05:00 committed by GitHub
parent edf56ee970
commit 5cde50dee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -314,6 +314,14 @@ func compile(
computedRoutes.PortedConfigs[port] = mc
}
if len(computedRoutes.PortedConfigs) == 0 {
// This service only exposes a "mesh" port, so it cannot be another service's upstream.
return &ComputedRoutesResult{
ID: computedRoutesID,
Data: nil, // returning nil signals a delete is requested
}
}
return &ComputedRoutesResult{
ID: computedRoutesID,
OwnerID: parentServiceID,

View File

@ -160,6 +160,24 @@ func TestGenerateComputedRoutes(t *testing.T) {
run(t, related, expect, nil)
})
t.Run("aligned service in mesh but no actual ports", func(t *testing.T) {
related := loader.NewRelatedResources().
AddComputedRoutesIDs(apiComputedRoutesID).
AddResources(newService("api", &pbcatalog.Service{
Workloads: &pbcatalog.WorkloadSelector{
Prefixes: []string{"api-"},
},
Ports: []*pbcatalog.ServicePort{
{TargetPort: "mesh", Protocol: pbcatalog.Protocol_PROTOCOL_MESH},
},
}))
expect := []*ComputedRoutesResult{{
ID: apiComputedRoutesID,
Data: nil,
}}
run(t, related, expect, nil)
})
t.Run("tcp service with default route", func(t *testing.T) {
apiServiceData := &pbcatalog.Service{
Workloads: &pbcatalog.WorkloadSelector{