Add tenancy tests for routes controller (#19706)

This commit is contained in:
Ganesh S 2023-11-22 21:52:10 +05:30 committed by GitHub
parent 0fdc2ac5e9
commit ba2422596f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2692 additions and 2653 deletions

View File

@ -31,11 +31,13 @@ type controllerSuite struct {
ctx context.Context
client *rtest.Client
rt controller.Runtime
tenancies []*pbresource.Tenancy
}
func (suite *controllerSuite) SetupTest() {
suite.ctx = testutil.TestContext(suite.T())
client := svctest.RunResourceService(suite.T(), types.Register, catalog.RegisterTypes)
suite.tenancies = rtest.TestTenancies()
client := svctest.RunResourceServiceWithTenancies(suite.T(), types.Register, catalog.RegisterTypes)
suite.rt = controller.Runtime{
Client: client,
Logger: testutil.Logger(suite.T()),
@ -49,23 +51,25 @@ func (suite *controllerSuite) TestController() {
mgr.SetRaftLeader(true)
go mgr.Run(suite.ctx)
suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) {
backendName := func(name, port string) string {
return fmt.Sprintf("catalog.v2beta1.Service/default.local.default/%s?port=%s", name, port)
return fmt.Sprintf("catalog.v2beta1.Service/%s.local.%s/%s?port=%s", tenancy.Partition, tenancy.Namespace, name, port)
}
var (
apiServiceRef = rtest.Resource(pbcatalog.ServiceType, "api").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
Reference("")
fooServiceRef = rtest.Resource(pbcatalog.ServiceType, "foo").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
Reference("")
barServiceRef = rtest.Resource(pbcatalog.ServiceType, "bar").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
Reference("")
computedRoutesID = rtest.Resource(pbmesh.ComputedRoutesType, "api").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
ID()
)
@ -84,7 +88,7 @@ func (suite *controllerSuite) TestController() {
}
_ = rtest.Resource(pbcatalog.ServiceType, "api").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), apiServiceData).
Write(suite.T(), suite.client)
@ -140,7 +144,7 @@ func (suite *controllerSuite) TestController() {
}
_ = rtest.Resource(pbcatalog.ServiceType, "api").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), apiServiceData).
Write(suite.T(), suite.client)
@ -158,8 +162,8 @@ func (suite *controllerSuite) TestController() {
},
}
_ = rtest.Resource(pbcatalog.ServiceType, "foo").
WithTenancy(resource.DefaultNamespacedTenancy()).
fooService := rtest.Resource(pbcatalog.ServiceType, "foo").
WithTenancy(tenancy).
WithData(suite.T(), fooServiceData).
Write(suite.T(), suite.client)
@ -280,7 +284,7 @@ func (suite *controllerSuite) TestController() {
tcpRoute1 := &pbmesh.TCPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "tcp"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "tcp"),
},
Rules: []*pbmesh.TCPRouteRule{{
BackendRefs: []*pbmesh.TCPBackendRef{{
@ -289,15 +293,15 @@ func (suite *controllerSuite) TestController() {
}},
}
tcpRoute1ID := rtest.Resource(pbmesh.TCPRouteType, "api-tcp-route1").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), tcpRoute1).
Write(suite.T(), suite.client).
Id
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http2"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http2"),
},
Rules: []*pbmesh.HTTPRouteRule{{
BackendRefs: []*pbmesh.HTTPBackendRef{{
@ -306,14 +310,14 @@ func (suite *controllerSuite) TestController() {
}},
}
httpRoute1ID := rtest.Resource(pbmesh.HTTPRouteType, "api-http-route1").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), httpRoute1).
Write(suite.T(), suite.client).
Id
grpcRoute1 := &pbmesh.GRPCRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "grpc"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "grpc"),
},
Rules: []*pbmesh.GRPCRouteRule{{
BackendRefs: []*pbmesh.GRPCBackendRef{{
@ -322,7 +326,7 @@ func (suite *controllerSuite) TestController() {
}},
}
grpcRoute1ID := rtest.Resource(pbmesh.GRPCRouteType, "api-grpc-route1").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), grpcRoute1).
Write(suite.T(), suite.client).
Id
@ -462,7 +466,7 @@ func (suite *controllerSuite) TestController() {
tcpRoute2 := &pbmesh.TCPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "tcp"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "tcp"),
},
Rules: []*pbmesh.TCPRouteRule{{
BackendRefs: []*pbmesh.TCPBackendRef{{
@ -471,15 +475,15 @@ func (suite *controllerSuite) TestController() {
}},
}
tcpRoute2ID := rtest.Resource(pbmesh.TCPRouteType, "api-tcp-route2").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), tcpRoute2).
Write(suite.T(), suite.client).
Id
httpRoute2 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http2"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http2"),
},
Rules: []*pbmesh.HTTPRouteRule{{
Matches: []*pbmesh.HTTPRouteMatch{{
@ -494,14 +498,14 @@ func (suite *controllerSuite) TestController() {
}},
}
httpRoute2ID := rtest.Resource(pbmesh.HTTPRouteType, "api-http-route2").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), httpRoute2).
Write(suite.T(), suite.client).
Id
grpcRoute2 := &pbmesh.GRPCRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "grpc"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "grpc"),
},
Rules: []*pbmesh.GRPCRouteRule{{
Matches: []*pbmesh.GRPCRouteMatch{{
@ -517,7 +521,7 @@ func (suite *controllerSuite) TestController() {
}},
}
grpcRoute2ID := rtest.Resource(pbmesh.GRPCRouteType, "api-grpc-route2").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), grpcRoute2).
Write(suite.T(), suite.client).
Id
@ -697,11 +701,11 @@ func (suite *controllerSuite) TestController() {
suite.client.WaitForStatusCondition(t, grpcRoute1ID, StatusKey, ConditionXRouteOK)
suite.client.WaitForStatusCondition(t, tcpRoute2ID, StatusKey,
ConditionMissingBackendRef(newRef(pbcatalog.ServiceType, "bar")))
ConditionMissingBackendRef(newRef(pbcatalog.ServiceType, "bar", tenancy)))
suite.client.WaitForStatusCondition(t, httpRoute2ID, StatusKey,
ConditionMissingBackendRef(newRef(pbcatalog.ServiceType, "bar")))
ConditionMissingBackendRef(newRef(pbcatalog.ServiceType, "bar", tenancy)))
suite.client.WaitForStatusCondition(t, grpcRoute2ID, StatusKey,
ConditionMissingBackendRef(newRef(pbcatalog.ServiceType, "bar")))
ConditionMissingBackendRef(newRef(pbcatalog.ServiceType, "bar", tenancy)))
})
// Update the route2 routes to point to a real service, but overlap in
@ -715,7 +719,7 @@ func (suite *controllerSuite) TestController() {
tcpRoute2 = &pbmesh.TCPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.TCPRouteRule{{
BackendRefs: []*pbmesh.TCPBackendRef{{
@ -724,13 +728,13 @@ func (suite *controllerSuite) TestController() {
}},
}
rtest.ResourceID(tcpRoute2ID).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), tcpRoute2).
Write(suite.T(), suite.client)
httpRoute2 = &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "grpc"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "grpc"),
},
Rules: []*pbmesh.HTTPRouteRule{{
Matches: []*pbmesh.HTTPRouteMatch{{
@ -745,13 +749,13 @@ func (suite *controllerSuite) TestController() {
}},
}
rtest.ResourceID(httpRoute2ID).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), httpRoute2).
Write(suite.T(), suite.client)
grpcRoute2 = &pbmesh.GRPCRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "tcp"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "tcp"),
},
Rules: []*pbmesh.GRPCRouteRule{{
Matches: []*pbmesh.GRPCRouteMatch{{
@ -767,7 +771,7 @@ func (suite *controllerSuite) TestController() {
}},
}
rtest.ResourceID(grpcRoute2ID).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), grpcRoute2).
Write(suite.T(), suite.client)
@ -905,11 +909,11 @@ func (suite *controllerSuite) TestController() {
suite.client.WaitForStatusCondition(t, grpcRoute1ID, StatusKey, ConditionXRouteOK)
suite.client.WaitForStatusCondition(t, tcpRoute2ID, StatusKey,
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api"), "http", pbmesh.HTTPRouteType))
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http", pbmesh.HTTPRouteType))
suite.client.WaitForStatusCondition(t, httpRoute2ID, StatusKey,
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api"), "grpc", pbmesh.GRPCRouteType))
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "grpc", pbmesh.GRPCRouteType))
suite.client.WaitForStatusCondition(t, grpcRoute2ID, StatusKey,
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api"), "tcp", pbmesh.TCPRouteType))
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "tcp", pbmesh.TCPRouteType))
})
// - Delete the bad routes
@ -930,7 +934,7 @@ func (suite *controllerSuite) TestController() {
// Re-create with newarly the same data (wildcard port now) with a newer name.
grpcRoute1 = &pbmesh.GRPCRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), ""),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), ""),
},
Rules: []*pbmesh.GRPCRouteRule{{
BackendRefs: []*pbmesh.GRPCBackendRef{{
@ -939,7 +943,7 @@ func (suite *controllerSuite) TestController() {
}},
}
grpcRoute1ID = rtest.Resource(pbmesh.GRPCRouteType, "zzz-bad-route").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), grpcRoute1).
Write(suite.T(), suite.client).
Id
@ -1069,9 +1073,9 @@ func (suite *controllerSuite) TestController() {
}
suite.client.WaitForStatusConditions(t, grpcRoute1ID, StatusKey,
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api"), "http", pbmesh.HTTPRouteType),
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api"), "http2", pbmesh.HTTPRouteType),
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api"), "tcp", pbmesh.TCPRouteType))
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http", pbmesh.HTTPRouteType),
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http2", pbmesh.HTTPRouteType),
ConditionConflictNotBoundToParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "tcp", pbmesh.TCPRouteType))
lastVersion = requireNewComputedRoutesVersion(t, suite.client, computedRoutesID, "" /*no change*/, expect)
@ -1094,8 +1098,8 @@ func (suite *controllerSuite) TestController() {
},
}
_ = rtest.Resource(pbcatalog.ServiceType, "api").
WithTenancy(resource.DefaultNamespacedTenancy()).
apiService := rtest.Resource(pbcatalog.ServiceType, "api").
WithTenancy(tenancy).
WithData(suite.T(), apiServiceData).
Write(suite.T(), suite.client)
@ -1103,17 +1107,17 @@ func (suite *controllerSuite) TestController() {
suite.client.WaitForDeletion(t, computedRoutesID)
suite.client.WaitForStatusCondition(t, tcpRoute1ID, StatusKey,
ConditionParentRefOutsideMesh(newRef(pbcatalog.ServiceType, "api")))
ConditionParentRefOutsideMesh(newRef(pbcatalog.ServiceType, "api", tenancy)))
suite.client.WaitForStatusCondition(t, httpRoute1ID, StatusKey,
ConditionParentRefOutsideMesh(newRef(pbcatalog.ServiceType, "api")))
ConditionParentRefOutsideMesh(newRef(pbcatalog.ServiceType, "api", tenancy)))
suite.client.WaitForStatusCondition(t, grpcRoute1ID, StatusKey,
ConditionParentRefOutsideMesh(newRef(pbcatalog.ServiceType, "api")))
ConditionParentRefOutsideMesh(newRef(pbcatalog.ServiceType, "api", tenancy)))
})
// Get down to just 2 ports for all relevant services.
for _, name := range []string{"foo", "bar", "api"} {
_ = rtest.Resource(pbcatalog.ServiceType, name).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), &pbcatalog.Service{
Workloads: &pbcatalog.WorkloadSelector{
Prefixes: []string{name + "-"},
@ -1138,7 +1142,7 @@ func (suite *controllerSuite) TestController() {
}},
}
httpRoute1ID = rtest.Resource(pbmesh.HTTPRouteType, "route1").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), httpRoute1).
Write(suite.T(), suite.client).
Id
@ -1148,10 +1152,10 @@ func (suite *controllerSuite) TestController() {
barLastVersion string
fooComputedRoutesID = rtest.Resource(pbmesh.ComputedRoutesType, "foo").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
ID()
barComputedRoutesID = rtest.Resource(pbmesh.ComputedRoutesType, "bar").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
ID()
)
@ -1253,7 +1257,7 @@ func (suite *controllerSuite) TestController() {
}},
}
httpRoute1ID = rtest.Resource(pbmesh.HTTPRouteType, "route1").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(suite.T(), httpRoute1).
Write(suite.T(), suite.client).
Id
@ -1295,6 +1299,23 @@ func (suite *controllerSuite) TestController() {
barLastVersion = requireNewComputedRoutesVersion(t, suite.client, barComputedRoutesID, barLastVersion, expectBar)
suite.client.WaitForStatusCondition(t, httpRoute1ID, StatusKey, ConditionXRouteOK)
resourcesToDelete := []*pbresource.ID{
apiService.Id,
fooService.Id,
tcpRoute1ID,
tcpRoute2ID,
grpcRoute1ID,
grpcRoute2ID,
httpRoute1ID,
httpRoute2ID,
}
for _, id := range resourcesToDelete {
suite.client.MustDelete(t, id)
suite.client.WaitForDeletion(t, id)
}
})
})
}
@ -1338,3 +1359,15 @@ func requireNewComputedRoutesVersion(
func TestController(t *testing.T) {
suite.Run(t, new(controllerSuite))
}
func (suite *controllerSuite) runTestCaseWithTenancies(testFunc func(*pbresource.Tenancy)) {
for _, tenancy := range suite.tenancies {
suite.Run(suite.appendTenancyInfo(tenancy), func() {
testFunc(tenancy)
})
}
}
func (suite *controllerSuite) appendTenancyInfo(tenancy *pbresource.Tenancy) string {
return fmt.Sprintf("%s_Namespace_%s_Partition", tenancy.Namespace, tenancy.Partition)
}

View File

@ -29,6 +29,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
types.Register(registry)
catalog.RegisterTypes(registry)
for _, tenancy := range rtest.TestTenancies() {
run := func(
t *testing.T,
related *loader.RelatedResources,
@ -59,7 +60,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
newService := func(name string, data *pbcatalog.Service) *types.DecodedService {
svc := rtest.Resource(pbcatalog.ServiceType, name).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(t, data).Build()
rtest.ValidateAndNormalize(t, registry, svc)
return rtest.MustDecode[*pbcatalog.Service](t, svc)
@ -67,21 +68,21 @@ func TestGenerateComputedRoutes(t *testing.T) {
newHTTPRoute := func(name string, data *pbmesh.HTTPRoute) *types.DecodedHTTPRoute {
svc := rtest.Resource(pbmesh.HTTPRouteType, name).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(t, data).Build()
rtest.ValidateAndNormalize(t, registry, svc)
return rtest.MustDecode[*pbmesh.HTTPRoute](t, svc)
}
newGRPCRoute := func(name string, data *pbmesh.GRPCRoute) *types.DecodedGRPCRoute {
svc := rtest.Resource(pbmesh.GRPCRouteType, name).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(t, data).Build()
rtest.ValidateAndNormalize(t, registry, svc)
return rtest.MustDecode[*pbmesh.GRPCRoute](t, svc)
}
newTCPRoute := func(name string, data *pbmesh.TCPRoute) *types.DecodedTCPRoute {
svc := rtest.Resource(pbmesh.TCPRouteType, name).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(t, data).Build()
rtest.ValidateAndNormalize(t, registry, svc)
return rtest.MustDecode[*pbmesh.TCPRoute](t, svc)
@ -89,7 +90,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
newDestPolicy := func(name string, data *pbmesh.DestinationPolicy) *types.DecodedDestinationPolicy {
policy := rtest.Resource(pbmesh.DestinationPolicyType, name).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(t, data).Build()
rtest.ValidateAndNormalize(t, registry, policy)
return rtest.MustDecode[*pbmesh.DestinationPolicy](t, policy)
@ -97,37 +98,37 @@ func TestGenerateComputedRoutes(t *testing.T) {
newFailPolicy := func(name string, data *pbcatalog.FailoverPolicy) *types.DecodedFailoverPolicy {
policy := rtest.Resource(pbcatalog.FailoverPolicyType, name).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
WithData(t, data).Build()
rtest.ValidateAndNormalize(t, registry, policy)
return rtest.MustDecode[*pbcatalog.FailoverPolicy](t, policy)
}
backendName := func(name, port string) string {
return fmt.Sprintf("catalog.v2beta1.Service/default.local.default/%s?port=%s", name, port)
return fmt.Sprintf("catalog.v2beta1.Service/%s.local.%s/%s?port=%s", tenancy.Partition, tenancy.Namespace, name, port)
}
var (
apiServiceID = rtest.Resource(pbcatalog.ServiceType, "api").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
ID()
apiServiceRef = resource.Reference(apiServiceID, "")
apiComputedRoutesID = rtest.Resource(pbmesh.ComputedRoutesType, "api").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
ID()
fooServiceID = rtest.Resource(pbcatalog.ServiceType, "foo").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
ID()
fooServiceRef = resource.Reference(fooServiceID, "")
barServiceID = rtest.Resource(pbcatalog.ServiceType, "bar").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
ID()
barServiceRef = resource.Reference(barServiceID, "")
deadServiceID = rtest.Resource(pbcatalog.ServiceType, "dead").
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
ID()
deadServiceRef = resource.Reference(deadServiceID, "")
)
@ -378,7 +379,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
tcpRoute1 := &pbmesh.TCPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "tcp"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "tcp"),
},
Rules: []*pbmesh.TCPRouteRule{{
BackendRefs: []*pbmesh.TCPBackendRef{{
@ -389,8 +390,8 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http2"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http2"),
},
Rules: []*pbmesh.HTTPRouteRule{{
BackendRefs: []*pbmesh.HTTPBackendRef{{
@ -401,7 +402,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
grpcRoute1 := &pbmesh.GRPCRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "grpc"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "grpc"),
},
Rules: []*pbmesh.GRPCRouteRule{{
BackendRefs: []*pbmesh.GRPCBackendRef{{
@ -427,9 +428,9 @@ func TestGenerateComputedRoutes(t *testing.T) {
BoundReferences: []*pbresource.Reference{
apiServiceRef,
fooServiceRef,
newRef(pbmesh.GRPCRouteType, "api-grpc-route1"),
newRef(pbmesh.HTTPRouteType, "api-http-route1"),
newRef(pbmesh.TCPRouteType, "api-tcp-route1"),
newRef(pbmesh.GRPCRouteType, "api-grpc-route1", tenancy),
newRef(pbmesh.HTTPRouteType, "api-http-route1", tenancy),
newRef(pbmesh.TCPRouteType, "api-tcp-route1", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
"tcp": {
@ -578,7 +579,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), ""),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), ""),
},
Rules: []*pbmesh.HTTPRouteRule{{
BackendRefs: []*pbmesh.HTTPBackendRef{{
@ -635,7 +636,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
BoundReferences: []*pbresource.Reference{
apiServiceRef,
fooServiceRef,
newRef(pbmesh.HTTPRouteType, "api-http-route1"),
newRef(pbmesh.HTTPRouteType, "api-http-route1", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
// note: tcp has been upgraded to http in the presence of an HTTPRoute
@ -672,7 +673,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), ""),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), ""),
},
Rules: []*pbmesh.HTTPRouteRule{{
BackendRefs: []*pbmesh.HTTPBackendRef{{
@ -692,7 +693,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
// Update this after the fact, but don't update the inner indexing in
// the 'related' struct.
{
httpRoute1.ParentRefs[0] = newParentRef(newRef(pbcatalog.ServiceType, "foo"), "")
httpRoute1.ParentRefs[0] = newParentRef(newRef(pbcatalog.ServiceType, "foo", tenancy), "")
apiHTTPRoute1.Data = httpRoute1
anyData, err := anypb.New(httpRoute1)
@ -766,7 +767,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
// Using bad parent port (www).
newParentRef(newRef(pbcatalog.ServiceType, "api"), "www"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "www"),
},
Rules: []*pbmesh.HTTPRouteRule{{
BackendRefs: []*pbmesh.HTTPBackendRef{{
@ -849,7 +850,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRouteData := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
// Using bad parent port (www).
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.HTTPRouteRule{{
BackendRefs: []*pbmesh.HTTPBackendRef{{
@ -862,7 +863,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
tcpRouteData := &pbmesh.TCPRoute{
ParentRefs: []*pbmesh.ParentReference{
// Using bad parent port (www).
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.TCPRouteRule{{
BackendRefs: []*pbmesh.TCPBackendRef{{
@ -980,7 +981,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.HTTPRouteRule{{
Matches: []*pbmesh.HTTPRouteMatch{{
@ -997,7 +998,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute2 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.HTTPRouteRule{{
Matches: []*pbmesh.HTTPRouteMatch{{
@ -1030,8 +1031,8 @@ func TestGenerateComputedRoutes(t *testing.T) {
apiServiceRef,
barServiceRef,
fooServiceRef,
newRef(pbmesh.HTTPRouteType, "api-http-route1"),
newRef(pbmesh.HTTPRouteType, "api-http-route2"),
newRef(pbmesh.HTTPRouteType, "api-http-route1", tenancy),
newRef(pbmesh.HTTPRouteType, "api-http-route2", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
"http": {
@ -1115,7 +1116,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.HTTPRouteRule{{
Matches: []*pbmesh.HTTPRouteMatch{{
@ -1142,7 +1143,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
BoundReferences: []*pbresource.Reference{
apiServiceRef,
fooServiceRef,
newRef(pbmesh.HTTPRouteType, "api-http-route1"),
newRef(pbmesh.HTTPRouteType, "api-http-route1", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
"http": {
@ -1195,7 +1196,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.HTTPRouteRule{{
BackendRefs: []*pbmesh.HTTPBackendRef{{
@ -1217,7 +1218,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
Data: &pbmesh.ComputedRoutes{
BoundReferences: []*pbresource.Reference{
apiServiceRef,
newRef(pbmesh.HTTPRouteType, "api-http-route1"),
newRef(pbmesh.HTTPRouteType, "api-http-route1", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
"http": {
@ -1260,7 +1261,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
grpcRoute1 := &pbmesh.GRPCRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "grpc"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "grpc"),
},
Rules: []*pbmesh.GRPCRouteRule{{
BackendRefs: []*pbmesh.GRPCBackendRef{{
@ -1282,7 +1283,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
Data: &pbmesh.ComputedRoutes{
BoundReferences: []*pbresource.Reference{
apiServiceRef,
newRef(pbmesh.GRPCRouteType, "api-grpc-route1"),
newRef(pbmesh.GRPCRouteType, "api-grpc-route1", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
"grpc": {
@ -1325,7 +1326,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
tcpRoute1 := &pbmesh.TCPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "tcp"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "tcp"),
},
Rules: []*pbmesh.TCPRouteRule{{
BackendRefs: []*pbmesh.TCPBackendRef{{
@ -1347,7 +1348,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
Data: &pbmesh.ComputedRoutes{
BoundReferences: []*pbresource.Reference{
apiServiceRef,
newRef(pbmesh.TCPRouteType, "api-tcp-route1"),
newRef(pbmesh.TCPRouteType, "api-tcp-route1", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
"tcp": {
@ -1394,7 +1395,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.HTTPRouteRule{{
BackendRefs: []*pbmesh.HTTPBackendRef{{
@ -1418,7 +1419,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
BoundReferences: []*pbresource.Reference{
apiServiceRef,
fooServiceRef,
newRef(pbmesh.HTTPRouteType, "api-http-route1"),
newRef(pbmesh.HTTPRouteType, "api-http-route1", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
"http": {
@ -1472,7 +1473,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.HTTPRouteRule{{
Matches: []*pbmesh.HTTPRouteMatch{{
@ -1514,8 +1515,8 @@ func TestGenerateComputedRoutes(t *testing.T) {
BoundReferences: []*pbresource.Reference{
apiServiceRef,
fooServiceRef,
newRef(pbmesh.DestinationPolicyType, "foo"),
newRef(pbmesh.HTTPRouteType, "api-http-route1"),
newRef(pbmesh.DestinationPolicyType, "foo", tenancy),
newRef(pbmesh.HTTPRouteType, "api-http-route1", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
"http": {
@ -1587,7 +1588,7 @@ func TestGenerateComputedRoutes(t *testing.T) {
httpRoute1 := &pbmesh.HTTPRoute{
ParentRefs: []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", tenancy), "http"),
},
Rules: []*pbmesh.HTTPRouteRule{{
Matches: []*pbmesh.HTTPRouteMatch{{
@ -1632,11 +1633,11 @@ func TestGenerateComputedRoutes(t *testing.T) {
OwnerID: apiServiceID,
Data: &pbmesh.ComputedRoutes{
BoundReferences: []*pbresource.Reference{
newRef(pbcatalog.FailoverPolicyType, "foo"),
newRef(pbcatalog.FailoverPolicyType, "foo", tenancy),
apiServiceRef,
barServiceRef,
fooServiceRef,
newRef(pbmesh.HTTPRouteType, "api-http-route1"),
newRef(pbmesh.HTTPRouteType, "api-http-route1", tenancy),
},
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{
"http": {
@ -1681,4 +1682,5 @@ func TestGenerateComputedRoutes(t *testing.T) {
}}
run(t, related, expect, nil)
})
}
}

View File

@ -52,11 +52,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
t.Run("with no service", func(t *testing.T) {
sg := newTestServiceGetter()
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), ""),
newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), ""),
}, nil)
require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionMissingParentRef(
newRef(pbcatalog.ServiceType, "api"),
newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
))
})
@ -65,11 +65,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"http": pbcatalog.Protocol_PROTOCOL_HTTP,
}))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), ""),
newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), ""),
}, nil)
require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionParentRefOutsideMesh(
newRef(pbcatalog.ServiceType, "api"),
newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
))
})
@ -79,11 +79,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH,
}))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "mesh"),
newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "mesh"),
}, nil)
require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionParentRefUsingMeshPort(
newRef(pbcatalog.ServiceType, "api"),
newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
"mesh",
))
})
@ -94,11 +94,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH,
}))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "web"),
newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "web"),
}, nil)
require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionUnknownParentRefPort(
newRef(pbcatalog.ServiceType, "api"),
newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
"web",
))
})
@ -109,7 +109,7 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH,
}))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), ""),
newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), ""),
}, nil)
require.Empty(t, got)
})
@ -120,7 +120,7 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH,
}))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"),
newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "http"),
}, nil)
require.Empty(t, got)
})
@ -130,11 +130,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
t.Run("with no service", func(t *testing.T) {
sg := newTestServiceGetter()
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "", ""),
newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "", ""),
})
require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionMissingBackendRef(
newRef(pbcatalog.ServiceType, "api"),
newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
))
})
@ -143,11 +143,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"http": pbcatalog.Protocol_PROTOCOL_HTTP,
}))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "", ""),
newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "", ""),
})
require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionBackendRefOutsideMesh(
newRef(pbcatalog.ServiceType, "api"),
newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
))
})
@ -157,11 +157,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH,
}))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "mesh", ""),
newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "mesh", ""),
})
require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionBackendRefUsingMeshPort(
newRef(pbcatalog.ServiceType, "api"),
newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
"mesh",
))
})
@ -172,11 +172,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH,
}))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "web", ""),
newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "web", ""),
})
require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionUnknownBackendRefPort(
newRef(pbcatalog.ServiceType, "api"),
newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
"web",
))
})
@ -187,7 +187,7 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH,
}))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "", ""),
newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "", ""),
})
require.Empty(t, got)
})
@ -198,16 +198,20 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH,
}))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "http", ""),
newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "http", ""),
})
require.Empty(t, got)
})
})
}
func newRef(typ *pbresource.Type, name string) *pbresource.Reference {
func newRef(typ *pbresource.Type, name string, tenancy *pbresource.Tenancy) *pbresource.Reference {
if tenancy == nil {
tenancy = resource.DefaultNamespacedTenancy()
}
return rtest.Resource(typ, name).
WithTenancy(resource.DefaultNamespacedTenancy()).
WithTenancy(tenancy).
Reference("")
}