From 173fe11c2b6007969d9ee6fda0899b51d21bef7b Mon Sep 17 00:00:00 2001 From: Ganesh S Date: Tue, 12 Dec 2023 10:57:27 +0530 Subject: [PATCH] Refactor exported services controller tests (#19906) --- .../exportedservices/controller_test.go | 1083 ++++++++++++----- 1 file changed, 761 insertions(+), 322 deletions(-) diff --git a/internal/multicluster/internal/controllers/exportedservices/controller_test.go b/internal/multicluster/internal/controllers/exportedservices/controller_test.go index 667f4ef3a9..7386c3ef1c 100644 --- a/internal/multicluster/internal/controllers/exportedservices/controller_test.go +++ b/internal/multicluster/internal/controllers/exportedservices/controller_test.go @@ -53,388 +53,827 @@ func (suite *controllerSuite) SetupTest() { suite.isEnterprise = versiontest.IsEnterprise() } -func (suite *controllerSuite) TestReconcile() { - suite.runTestCaseWithTenancies(suite.reconcileTest) -} - 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) TestReconcile_DeleteOldCES_NoExportedServices() { + // This test's purpose is to ensure that we delete the + // already existing CES when no exported service resources + // are found. + + suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) { + oldCESData := &pbmulticluster.ComputedExportedServices{ + Consumers: []*pbmulticluster.ComputedExportedService{ + { + TargetRef: &pbresource.Reference{ + Type: pbcatalog.ServiceType, + Tenancy: tenancy, + Name: "svc0", + }, + Consumers: []*pbmulticluster.ComputedExportedServicesConsumer{ + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: "test-peer", + }, + }, + }, + }, + }, + } -func (suite *controllerSuite) appendTenancyInfo(tenancy *pbresource.Tenancy) string { - return fmt.Sprintf("%s_Namespace_%s_Partition", tenancy.Namespace, tenancy.Partition) -} + if suite.isEnterprise { + oldCESData.Consumers[0].Consumers = append(oldCESData.Consumers[0].Consumers, &pbmulticluster.ComputedExportedServicesConsumer{ + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: "part-n", + }, + }) + } -func (suite *controllerSuite) getComputedExportedSvc(id *pbresource.ID) *pbmulticluster.ComputedExportedServices { - computedExportedService := suite.client.RequireResourceExists(suite.T(), id) - decodedComputedExportedService := rtest.MustDecode[*pbmulticluster.ComputedExportedServices](suite.T(), computedExportedService) - return decodedComputedExportedService.Data -} + oldCES := rtest.Resource(pbmulticluster.ComputedExportedServicesType, "global"). + WithData(suite.T(), oldCESData). + WithTenancy(&pbresource.Tenancy{Partition: tenancy.Partition}). + Write(suite.T(), suite.client) + require.NotNil(suite.T(), oldCES) -func (suite *controllerSuite) reconcileTest(tenancy *pbresource.Tenancy) { - id := rtest.Resource(pbmulticluster.ComputedExportedServicesType, "global").WithTenancy(&pbresource.Tenancy{ - Partition: tenancy.Partition, - }).ID() - require.NotNil(suite.T(), id) + err := suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: oldCES.Id}) + require.NoError(suite.T(), err) - svc1 := rtest.Resource(pbcatalog.ServiceType, "svc1"). - WithData(suite.T(), &pbcatalog.Service{ - Ports: []*pbcatalog.ServicePort{ - {TargetPort: "http", Protocol: pbcatalog.Protocol_PROTOCOL_HTTP}, - }, - }). - WithTenancy(tenancy). - Write(suite.T(), suite.client) + suite.client.RequireResourceNotFound(suite.T(), oldCES.Id) + }) +} - exportedSvcData := &pbmulticluster.ExportedServices{ - Services: []string{"svc1", "svcx"}, - Consumers: []*pbmulticluster.ExportedServicesConsumer{{ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{ - Peer: "peer-0", - }}}, - } +func (suite *controllerSuite) TestReconcile_DeleteOldCES_NoMatchingServices() { + // This test's purpose is to ensure that we delete the + // already existing CES when the exported services configs + // don't cover any services present in the partition. + + suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) { + oldCESData := &pbmulticluster.ComputedExportedServices{ + Consumers: []*pbmulticluster.ComputedExportedService{ + { + TargetRef: &pbresource.Reference{ + Type: pbcatalog.ServiceType, + Tenancy: tenancy, + Name: "svc0", + }, + Consumers: []*pbmulticluster.ComputedExportedServicesConsumer{ + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: "test-peer", + }, + }, + }, + }, + }, + } - if suite.isEnterprise { - exportedSvcData.Consumers = append(exportedSvcData.Consumers, &pbmulticluster.ExportedServicesConsumer{ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Partition{ - Partition: "part-0", - }}) - } - expSvc := rtest.Resource(pbmulticluster.ExportedServicesType, "expsvc").WithData(suite.T(), exportedSvcData).WithTenancy(tenancy).Write(suite.T(), suite.client) - require.NotNil(suite.T(), expSvc) + if suite.isEnterprise { + oldCESData.Consumers[0].Consumers = append(oldCESData.Consumers[0].Consumers, &pbmulticluster.ComputedExportedServicesConsumer{ + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: "part-n", + }, + }) + } - err := suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) - actualComputedExportedService := suite.getComputedExportedSvc(id) - expectedComputedExportedService := getExpectation(tenancy, suite.isEnterprise, 0) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) + oldCES := rtest.Resource(pbmulticluster.ComputedExportedServicesType, "global"). + WithData(suite.T(), oldCESData). + WithTenancy(&pbresource.Tenancy{Partition: tenancy.Partition}). + Write(suite.T(), suite.client) + require.NotNil(suite.T(), oldCES) - rtest.Resource(pbcatalog.ServiceType, "svc2"). - WithData(suite.T(), &pbcatalog.Service{ - Ports: []*pbcatalog.ServicePort{ - {TargetPort: "http", Protocol: pbcatalog.Protocol_PROTOCOL_HTTP}, + exportedSvcData := &pbmulticluster.ExportedServices{ + Services: []string{"random-service-1", "random-service-2"}, + Consumers: []*pbmulticluster.ExportedServicesConsumer{ + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{Peer: "peer-1"}}, }, - }). - WithTenancy(tenancy). - Write(suite.T(), suite.client) + } + if suite.isEnterprise { + exportedSvcData.Consumers = append(exportedSvcData.Consumers, &pbmulticluster.ExportedServicesConsumer{ + ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Partition{ + Partition: "part-n", + }, + }) + } + suite.writeExportedService("exported-svcs", tenancy, exportedSvcData) + + if suite.isEnterprise { + nesData := &pbmulticluster.NamespaceExportedServices{ + Consumers: []*pbmulticluster.ExportedServicesConsumer{ + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Partition{Partition: "part-n"}}, + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{Peer: "peer-2"}}, + }, + } + suite.writeNamespaceExportedService("nes", tenancy, nesData) + } - svc0 := rtest.Resource(pbcatalog.ServiceType, "svc0"). - WithData(suite.T(), &pbcatalog.Service{ - Ports: []*pbcatalog.ServicePort{ - {TargetPort: "http", Protocol: pbcatalog.Protocol_PROTOCOL_HTTP}, + err := suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: oldCES.Id}) + require.NoError(suite.T(), err) + + suite.client.RequireResourceNotFound(suite.T(), oldCES.Id) + }) +} + +func (suite *controllerSuite) TestReconcile_SkipWritingNewCES() { + // This test's purpose is to ensure that we skip + // writing the new CES when there are no changes to + // the existing one + + suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) { + oldCESData := &pbmulticluster.ComputedExportedServices{ + Consumers: []*pbmulticluster.ComputedExportedService{ + { + TargetRef: &pbresource.Reference{ + Type: pbcatalog.ServiceType, + Tenancy: tenancy, + Name: "svc-0", + }, + Consumers: []*pbmulticluster.ComputedExportedServicesConsumer{ + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: "peer-1", + }, + }, + }, + }, }, - }). - WithTenancy(&pbresource.Tenancy{ - Partition: tenancy.Partition, - Namespace: "app", - }). - Write(suite.T(), suite.client) + } - exportedNamespaceSvcData := &pbmulticluster.NamespaceExportedServices{ - Consumers: []*pbmulticluster.ExportedServicesConsumer{{ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{ - Peer: "peer-1", - }}}, - } + if suite.isEnterprise { + oldCESData.Consumers[0].Consumers = append(oldCESData.Consumers[0].Consumers, &pbmulticluster.ComputedExportedServicesConsumer{ + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: "part-n", + }, + }) + } - nameexpSvc := rtest.Resource(pbmulticluster.NamespaceExportedServicesType, "namesvc").WithData(suite.T(), exportedNamespaceSvcData).WithTenancy(tenancy).Write(suite.T(), suite.client) - require.NotNil(suite.T(), nameexpSvc) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 1) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) + oldCES := rtest.Resource(pbmulticluster.ComputedExportedServicesType, "global"). + WithData(suite.T(), oldCESData). + WithTenancy(&pbresource.Tenancy{Partition: tenancy.Partition}). + Write(suite.T(), suite.client) + require.NotNil(suite.T(), oldCES) + + // Export the svc-0 service to just a peer + exportedSvcData := &pbmulticluster.ExportedServices{ + Services: []string{"svc-0"}, + Consumers: []*pbmulticluster.ExportedServicesConsumer{ + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{Peer: "peer-1"}}, + }, + } + _ = rtest.Resource(pbmulticluster.ExportedServicesType, "exported-svcs"). + WithData(suite.T(), exportedSvcData). + WithTenancy(tenancy). + Write(suite.T(), suite.client) + + if suite.isEnterprise { + // Export all services in a given partition to `part-n` partition + pesData := &pbmulticluster.PartitionExportedServices{ + Consumers: []*pbmulticluster.ExportedServicesConsumer{ + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Partition{Partition: "part-n"}}, + }, + } + _ = rtest.Resource(pbmulticluster.PartitionExportedServicesType, "pes"). + WithData(suite.T(), pesData). + WithTenancy(&pbresource.Tenancy{Partition: tenancy.Partition}). + Write(suite.T(), suite.client) + } - svc3 := rtest.Resource(pbcatalog.ServiceType, "svc3"). - WithData(suite.T(), &pbcatalog.Service{ + svcData := &pbcatalog.Service{ Ports: []*pbcatalog.ServicePort{ {TargetPort: "http", Protocol: pbcatalog.Protocol_PROTOCOL_HTTP}, }, - }). - WithTenancy(tenancy). - Write(suite.T(), suite.client) + } + _ = rtest.Resource(pbcatalog.ServiceType, "svc-0"). + WithData(suite.T(), svcData). + WithTenancy(tenancy). + Write(suite.T(), suite.client) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 2) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) - - suite.client.MustDelete(suite.T(), svc3.Id) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) - - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 3) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) - - partitionedExportedSvcData := &pbmulticluster.PartitionExportedServices{ - Consumers: []*pbmulticluster.ExportedServicesConsumer{{ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{ - Peer: "peer-1", - }}, {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{ - Peer: "peer-2", - }}}, - } + err := suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: oldCES.Id}) + require.NoError(suite.T(), err) - partexpSvc := rtest.Resource(pbmulticluster.PartitionExportedServicesType, "partsvc").WithData(suite.T(), partitionedExportedSvcData).WithTenancy(&pbresource.Tenancy{Partition: tenancy.Partition}).Write(suite.T(), suite.client) - require.NotNil(suite.T(), partexpSvc) + // Checking no-op with version + suite.client.RequireVersionUnchanged(suite.T(), oldCES.Id, oldCES.Version) + }) +} - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 4) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) +func (suite *controllerSuite) TestReconcile_ComputeCES() { + suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) { + suite.writeService("svc-0", tenancy) - svc4 := rtest.Resource(pbcatalog.ServiceType, "svc4"). - WithData(suite.T(), &pbcatalog.Service{ - Ports: []*pbcatalog.ServicePort{ - {TargetPort: "http", Protocol: pbcatalog.Protocol_PROTOCOL_HTTP}, + if suite.isEnterprise { + suite.writeService("svc-1", tenancy) + suite.writeService("svc-2", tenancy) + } + + // Export the svc-0 service to just peers + exportedSvcData := &pbmulticluster.ExportedServices{ + Services: []string{"svc-0"}, + Consumers: []*pbmulticluster.ExportedServicesConsumer{ + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{Peer: "peer-1"}}, + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{Peer: "peer-2"}}, }, - }). - WithTenancy(&pbresource.Tenancy{ - Partition: tenancy.Partition, - Namespace: "app", - }). - Write(suite.T(), suite.client) + } + suite.writeExportedService("exp-svc-0", tenancy, exportedSvcData) + + if suite.isEnterprise { + nesData := &pbmulticluster.NamespaceExportedServices{ + Consumers: []*pbmulticluster.ExportedServicesConsumer{ + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{Peer: "peer-2"}}, + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Partition{Partition: "part-1"}}, + }, + } + suite.writeNamespaceExportedService("nes", tenancy, nesData) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 5) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) + // Export all services in a given partition to `part-n` partition + pesData := &pbmulticluster.PartitionExportedServices{ + Consumers: []*pbmulticluster.ExportedServicesConsumer{ + {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Partition{Partition: "part-n"}}, + }, + } + suite.writePartitionedExportedService("pes", tenancy, pesData) + } - suite.client.MustDelete(suite.T(), svc4.Id) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) + id := rtest.Resource(pbmulticluster.ComputedExportedServicesType, "global").WithTenancy(&pbresource.Tenancy{Partition: tenancy.Partition}).ID() + require.NotNil(suite.T(), id) + + err := suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) + require.NoError(suite.T(), err) + + computedCES := suite.getComputedExportedSvc(id) + + var expectedCES *pbmulticluster.ComputedExportedServices + if suite.isEnterprise { + expectedCES = &pbmulticluster.ComputedExportedServices{ + Consumers: []*pbmulticluster.ComputedExportedService{ + { + TargetRef: &pbresource.Reference{ + Type: pbcatalog.ServiceType, + Tenancy: tenancy, + Name: "svc-0", + }, + Consumers: []*pbmulticluster.ComputedExportedServicesConsumer{ + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: "peer-1", + }, + }, + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: "peer-2", + }, + }, + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: "part-1", + }, + }, + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: "part-n", + }, + }, + }, + }, + { + TargetRef: &pbresource.Reference{ + Type: pbcatalog.ServiceType, + Tenancy: tenancy, + Name: "svc-1", + }, + Consumers: []*pbmulticluster.ComputedExportedServicesConsumer{ + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: "peer-2", + }, + }, + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: "part-1", + }, + }, + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: "part-n", + }, + }, + }, + }, + { + TargetRef: &pbresource.Reference{ + Type: pbcatalog.ServiceType, + Tenancy: tenancy, + Name: "svc-2", + }, + Consumers: []*pbmulticluster.ComputedExportedServicesConsumer{ + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: "peer-2", + }, + }, + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: "part-1", + }, + }, + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: "part-n", + }, + }, + }, + }, + }, + } + } else { + expectedCES = &pbmulticluster.ComputedExportedServices{ + Consumers: []*pbmulticluster.ComputedExportedService{ + { + TargetRef: &pbresource.Reference{ + Type: pbcatalog.ServiceType, + Tenancy: resource.DefaultNamespacedTenancy(), + Name: "svc-0", + }, + Consumers: []*pbmulticluster.ComputedExportedServicesConsumer{ + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: "peer-1", + }, + }, + { + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: "peer-2", + }, + }, + }, + }, + }, + } + } - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 6) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) + prototest.AssertDeepEqual(suite.T(), expectedCES, computedCES) + }) +} - rtest.Resource(pbcatalog.ServiceType, "svc5"). - WithData(suite.T(), &pbcatalog.Service{ - Ports: []*pbcatalog.ServicePort{ - {TargetPort: "http", Protocol: pbcatalog.Protocol_PROTOCOL_HTTP}, - }, - }). - WithTenancy(tenancy). - Write(suite.T(), suite.client) +func (suite *controllerSuite) TestController() { + // Run the controller manager + mgr := controller.NewManager(suite.client, suite.rt.Logger) + mgr.Register(Controller()) + mgr.SetRaftLeader(true) + go mgr.Run(suite.ctx) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) + suite.runTestCaseWithTenancies(func(tenancy *pbresource.Tenancy) { + id := rtest.Resource(pbmulticluster.ComputedExportedServicesType, "global").WithTenancy(&pbresource.Tenancy{ + Partition: tenancy.Partition, + }).ID() + require.NotNil(suite.T(), id) + + svc1 := suite.writeService("svc1", tenancy) + exportedSvcData := &pbmulticluster.ExportedServices{ + Services: []string{"svc1", "svcx"}, + Consumers: []*pbmulticluster.ExportedServicesConsumer{{ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{ + Peer: "peer-0", + }}}, + } - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 7) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) + if suite.isEnterprise { + exportedSvcData.Consumers = append(exportedSvcData.Consumers, &pbmulticluster.ExportedServicesConsumer{ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Partition{ + Partition: "part-0", + }}) + } - suite.client.MustDelete(suite.T(), partexpSvc.Id) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) + expSvc := suite.writeExportedService("expsvc", tenancy, exportedSvcData) + require.NotNil(suite.T(), expSvc) - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 8) + res := suite.client.WaitForResourceExists(suite.T(), id) + computedCES := suite.getComputedExportedSvc(id) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) + expectedComputedExportedService := constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("part-0", "partition"), + }), + ) - suite.client.MustDelete(suite.T(), nameexpSvc.Id) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) - actualComputedExportedService = suite.getComputedExportedSvc(id) + svc2 := suite.writeService("svc2", tenancy) + svc0 := suite.writeService("svc0", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app"}) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 9) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) + exportedNamespaceSvcData := &pbmulticluster.NamespaceExportedServices{ + Consumers: []*pbmulticluster.ExportedServicesConsumer{{ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{ + Peer: "peer-1", + }}}, + } + namespaceExportedSvc := suite.writeNamespaceExportedService("namesvc", tenancy, exportedNamespaceSvcData) + + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc2", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + }, + ), + ) - suite.client.MustDelete(suite.T(), expSvc.Id) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + svc3 := suite.writeService("svc3", tenancy) + + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc2", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc3", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + }, + ), + ) - suite.client.RequireResourceNotFound(suite.T(), id) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + suite.client.MustDelete(suite.T(), svc3.Id) + + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc2", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + }, + ), + ) - nameexpSvc1 := rtest.Resource(pbmulticluster.NamespaceExportedServicesType, "namesvc1").WithData(suite.T(), exportedNamespaceSvcData).WithTenancy(&pbresource.Tenancy{ - Partition: tenancy.Partition, - Namespace: "app", - }).Write(suite.T(), suite.client) - require.NotNil(suite.T(), nameexpSvc1) - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(&pbresource.Tenancy{ - Partition: tenancy.Partition, - Namespace: "app", - }, suite.isEnterprise, 10) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) - expSvc1 := rtest.Resource(pbmulticluster.ExportedServicesType, "expsvc1").WithData(suite.T(), exportedSvcData).WithTenancy(tenancy).Write(suite.T(), suite.client) - require.NotNil(suite.T(), expSvc1) + partitionedExportedSvcData := &pbmulticluster.PartitionExportedServices{ + Consumers: []*pbmulticluster.ExportedServicesConsumer{{ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{ + Peer: "peer-1", + }}, {ConsumerTenancy: &pbmulticluster.ExportedServicesConsumer_Peer{ + Peer: "peer-2", + }}}, + } + partExpService := suite.writePartitionedExportedService("partsvc", tenancy, partitionedExportedSvcData) + + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc0", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app", PeerName: resource.DefaultPeerName}), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc2", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + ) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + svc4 := suite.writeService("svc4", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app"}) + + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc0", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app", PeerName: resource.DefaultPeerName}), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc4", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app", PeerName: resource.DefaultPeerName}), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc2", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + ) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + suite.client.MustDelete(suite.T(), svc4.Id) + + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc0", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app", PeerName: resource.DefaultPeerName}), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc2", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + ) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + suite.writeService("svc5", tenancy) + + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc0", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app", PeerName: resource.DefaultPeerName}), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc2", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc5", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("peer-2", "peer"), + }, + ), + ) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + suite.client.MustDelete(suite.T(), partExpService.Id) + + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("peer-1", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc2", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc5", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + }, + ), + ) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + suite.client.MustDelete(suite.T(), namespaceExportedSvc.Id) + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + ) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + suite.client.MustDelete(suite.T(), expSvc.Id) + suite.client.WaitForDeletion(suite.T(), res.Id) + + namespaceExportedSvc = suite.writeNamespaceExportedService("namesvc1", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app"}, exportedNamespaceSvcData) + + res = suite.client.WaitForResourceExists(suite.T(), id) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc0", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app", PeerName: resource.DefaultPeerName}), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + }, + ), + ) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + expSvc = suite.writeExportedService("expsvc1", tenancy, exportedSvcData) + res = suite.client.WaitForNewVersion(suite.T(), id, res.Version) + computedCES = suite.getComputedExportedSvc(res.Id) + expectedComputedExportedService = constructComputedExportedServices( + constructComputedExportedService( + constructSvcReference("svc0", &pbresource.Tenancy{Partition: tenancy.Partition, Namespace: "app", PeerName: resource.DefaultPeerName}), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-1", "peer"), + }, + ), + constructComputedExportedService( + constructSvcReference("svc1", tenancy), + []*pbmulticluster.ComputedExportedServicesConsumer{ + suite.constructConsumer("peer-0", "peer"), + suite.constructConsumer("part-0", "partition"), + }, + ), + ) + prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, computedCES) + + suite.client.MustDelete(suite.T(), svc0.Id) + suite.client.MustDelete(suite.T(), svc1.Id) + suite.client.WaitForDeletion(suite.T(), res.Id) + + // Delete other resources + suite.client.MustDelete(suite.T(), svc2.Id) + suite.client.MustDelete(suite.T(), svc3.Id) + suite.client.MustDelete(suite.T(), expSvc.Id) + suite.client.MustDelete(suite.T(), namespaceExportedSvc.Id) + suite.client.MustDelete(suite.T(), partExpService.Id) + }) +} - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) - actualComputedExportedService = suite.getComputedExportedSvc(id) - expectedComputedExportedService = getExpectation(tenancy, suite.isEnterprise, 11) - prototest.AssertDeepEqual(suite.T(), expectedComputedExportedService, actualComputedExportedService) +func (suite *controllerSuite) runTestCaseWithTenancies(testFunc func(*pbresource.Tenancy)) { + for _, tenancy := range suite.tenancies { + suite.Run(suite.appendTenancyInfo(tenancy), func() { + testFunc(tenancy) + }) + } +} - suite.client.MustDelete(suite.T(), svc0.Id) - suite.client.MustDelete(suite.T(), svc1.Id) +func (suite *controllerSuite) appendTenancyInfo(tenancy *pbresource.Tenancy) string { + return fmt.Sprintf("%s_Namespace_%s_Partition", tenancy.Namespace, tenancy.Partition) +} - err = suite.reconciler.Reconcile(suite.ctx, suite.rt, controller.Request{ID: id}) - require.NoError(suite.T(), err) +func (suite *controllerSuite) getComputedExportedSvc(id *pbresource.ID) *pbmulticluster.ComputedExportedServices { + computedExportedService := suite.client.RequireResourceExists(suite.T(), id) + decodedComputedExportedService := rtest.MustDecode[*pbmulticluster.ComputedExportedServices](suite.T(), computedExportedService) + return decodedComputedExportedService.Data +} - suite.client.RequireResourceNotFound(suite.T(), id) +func (suite *controllerSuite) writeService(name string, tenancy *pbresource.Tenancy) *pbresource.Resource { + return rtest.Resource(pbcatalog.ServiceType, name). + WithData(suite.T(), &pbcatalog.Service{ + Ports: []*pbcatalog.ServicePort{ + {TargetPort: "http", Protocol: pbcatalog.Protocol_PROTOCOL_HTTP}, + }, + }). + WithTenancy(tenancy). + Write(suite.T(), suite.client) +} +func (suite *controllerSuite) writeExportedService(name string, tenancy *pbresource.Tenancy, data *pbmulticluster.ExportedServices) *pbresource.Resource { + return rtest.Resource(pbmulticluster.ExportedServicesType, name). + WithData(suite.T(), data). + WithTenancy(tenancy). + Write(suite.T(), suite.client) } -func getExpectation(tenancy *pbresource.Tenancy, isEnterprise bool, testCase int) *pbmulticluster.ComputedExportedServices { - makeCES := func(consumers ...*pbmulticluster.ComputedExportedService) *pbmulticluster.ComputedExportedServices { - return &pbmulticluster.ComputedExportedServices{ - Consumers: consumers, - } - } - makeConsumer := func(ref *pbresource.Reference, consumers ...*pbmulticluster.ComputedExportedServicesConsumer) *pbmulticluster.ComputedExportedService { - var actual []*pbmulticluster.ComputedExportedServicesConsumer - for _, c := range consumers { - _, ok := c.ConsumerTenancy.(*pbmulticluster.ComputedExportedServicesConsumer_Partition) - if (isEnterprise && ok) || !ok { - actual = append(actual, c) - } - } +func (suite *controllerSuite) writeNamespaceExportedService(name string, tenancy *pbresource.Tenancy, data *pbmulticluster.NamespaceExportedServices) *pbresource.Resource { + return rtest.Resource(pbmulticluster.NamespaceExportedServicesType, name). + WithData(suite.T(), data). + WithTenancy(tenancy). + Write(suite.T(), suite.client) +} + +func (suite *controllerSuite) writePartitionedExportedService(name string, tenancy *pbresource.Tenancy, data *pbmulticluster.PartitionExportedServices) *pbresource.Resource { + return rtest.Resource(pbmulticluster.PartitionExportedServicesType, name). + WithData(suite.T(), data). + WithTenancy(&pbresource.Tenancy{Partition: tenancy.Partition}). + Write(suite.T(), suite.client) +} - return &pbmulticluster.ComputedExportedService{ - TargetRef: ref, - Consumers: actual, +func (suite *controllerSuite) constructConsumer(name, consumerType string) *pbmulticluster.ComputedExportedServicesConsumer { + if consumerType == "peer" { + return &pbmulticluster.ComputedExportedServicesConsumer{ + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ + Peer: name, + }, } } - svc0Ref := &pbresource.Reference{ - Type: pbcatalog.ServiceType, - Tenancy: &pbresource.Tenancy{ - Partition: tenancy.Partition, - Namespace: "app", - PeerName: resource.DefaultPeerName, - }, - Name: "svc0", - } - svc1Ref := &pbresource.Reference{ - Type: pbcatalog.ServiceType, - Tenancy: tenancy, - Name: "svc1", - } - svc2Ref := &pbresource.Reference{ - Type: pbcatalog.ServiceType, - Tenancy: tenancy, - Name: "svc2", - } - svc3Ref := &pbresource.Reference{ - Type: pbcatalog.ServiceType, - Tenancy: tenancy, - Name: "svc3", - } - svc4Ref := &pbresource.Reference{ - Type: pbcatalog.ServiceType, - Tenancy: &pbresource.Tenancy{ - Partition: tenancy.Partition, - Namespace: "app", - PeerName: resource.DefaultPeerName, - }, - Name: "svc4", - } - svc5Ref := &pbresource.Reference{ - Type: pbcatalog.ServiceType, - Tenancy: tenancy, - Name: "svc5", - } - peer0Consumer := &pbmulticluster.ComputedExportedServicesConsumer{ - ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ - Peer: "peer-0", - }, + if !suite.isEnterprise { + return nil } - peer1Consumer := &pbmulticluster.ComputedExportedServicesConsumer{ - ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ - Peer: "peer-1", + + return &pbmulticluster.ComputedExportedServicesConsumer{ + ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ + Partition: name, }, } - peer2Consumer := &pbmulticluster.ComputedExportedServicesConsumer{ - ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Peer{ - Peer: "peer-2", - }, +} + +func constructComputedExportedService(ref *pbresource.Reference, consumers []*pbmulticluster.ComputedExportedServicesConsumer) *pbmulticluster.ComputedExportedService { + finalConsumers := make([]*pbmulticluster.ComputedExportedServicesConsumer, 0) + for _, c := range consumers { + if c == nil { + continue + } + + finalConsumers = append(finalConsumers, c) } - part0Consumer := &pbmulticluster.ComputedExportedServicesConsumer{ - ConsumerTenancy: &pbmulticluster.ComputedExportedServicesConsumer_Partition{ - Partition: "part-0", - }, + return &pbmulticluster.ComputedExportedService{ + TargetRef: ref, + Consumers: finalConsumers, } +} - switch testCase { - case 0: - return makeCES(makeConsumer(svc1Ref, peer0Consumer, part0Consumer)) - case 1: - return makeCES( - makeConsumer(svc1Ref, peer0Consumer, peer1Consumer, part0Consumer), - makeConsumer(svc2Ref, peer1Consumer), - ) - case 2: - return makeCES( - makeConsumer(svc1Ref, peer0Consumer, peer1Consumer, part0Consumer), - makeConsumer(svc2Ref, peer1Consumer), - makeConsumer(svc3Ref, peer1Consumer), - ) - case 3: - return makeCES( - makeConsumer(svc1Ref, peer0Consumer, peer1Consumer, part0Consumer), - makeConsumer(svc2Ref, peer1Consumer), - ) - case 4: - return makeCES( - makeConsumer(svc0Ref, peer1Consumer, peer2Consumer), - makeConsumer(svc1Ref, peer0Consumer, peer1Consumer, peer2Consumer, part0Consumer), - makeConsumer(svc2Ref, peer1Consumer, peer2Consumer), - ) - case 5: - return makeCES( - makeConsumer(svc0Ref, peer1Consumer, peer2Consumer), - makeConsumer(svc4Ref, peer1Consumer, peer2Consumer), - makeConsumer(svc1Ref, peer0Consumer, peer1Consumer, peer2Consumer, part0Consumer), - makeConsumer(svc2Ref, peer1Consumer, peer2Consumer), - ) - case 6: - return makeCES( - makeConsumer(svc0Ref, peer1Consumer, peer2Consumer), - makeConsumer(svc1Ref, peer0Consumer, peer1Consumer, peer2Consumer, part0Consumer), - makeConsumer(svc2Ref, peer1Consumer, peer2Consumer), - ) - case 7: - return makeCES( - makeConsumer(svc0Ref, peer1Consumer, peer2Consumer), - makeConsumer(svc1Ref, peer0Consumer, peer1Consumer, peer2Consumer, part0Consumer), - makeConsumer(svc2Ref, peer1Consumer, peer2Consumer), - makeConsumer(svc5Ref, peer1Consumer, peer2Consumer), - ) - case 8: - return makeCES( - makeConsumer(svc1Ref, peer0Consumer, peer1Consumer, part0Consumer), - makeConsumer(svc2Ref, peer1Consumer), - makeConsumer(svc5Ref, peer1Consumer), - ) - case 9: - return makeCES( - makeConsumer(svc1Ref, peer0Consumer, part0Consumer), - ) - case 10: - return makeCES( - makeConsumer(svc0Ref, peer1Consumer), - ) - case 11: - return makeCES( - makeConsumer(svc0Ref, peer1Consumer), - makeConsumer(svc1Ref, peer0Consumer, part0Consumer), - ) +func constructComputedExportedServices(consumers ...*pbmulticluster.ComputedExportedService) *pbmulticluster.ComputedExportedServices { + return &pbmulticluster.ComputedExportedServices{ + Consumers: consumers, } +} - return nil +func constructSvcReference(name string, tenancy *pbresource.Tenancy) *pbresource.Reference { + return &pbresource.Reference{ + Type: pbcatalog.ServiceType, + Tenancy: tenancy, + Name: name, + } }