From c46968df8a7a434e17885493507d56f904c9e2eb Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Fri, 24 Mar 2023 09:29:59 +0100 Subject: [PATCH] Rename local/broker transformers for clarity This makes the direction of transformers and syncers explicit. The documentation is updated to match. Signed-off-by: Stephen Kitt --- pkg/syncer/broker/syncer.go | 24 ++++++++++++------------ pkg/syncer/broker/syncer_test.go | 4 ++-- test/e2e/syncer/broker.go | 24 ++++++++++++------------ 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pkg/syncer/broker/syncer.go b/pkg/syncer/broker/syncer.go index 57cecc21..ef912896 100644 --- a/pkg/syncer/broker/syncer.go +++ b/pkg/syncer/broker/syncer.go @@ -51,11 +51,11 @@ type ResourceConfig struct { // LocalResourceType the type of the local resources to sync to the broker. LocalResourceType runtime.Object - // LocalTransform function used to transform a local resource to the equivalent broker resource. - LocalTransform syncer.TransformFunc + // TransformLocalToBroker function used to transform a local resource to the equivalent broker resource. + TransformLocalToBroker syncer.TransformFunc - // OnSuccessfulSync function invoked after a successful sync operation to the broker. - LocalOnSuccessfulSync syncer.OnSuccessfulSyncFunc + // OnSuccessfulSyncToBroker function invoked after a successful sync operation to the broker. + OnSuccessfulSyncToBroker syncer.OnSuccessfulSyncFunc // LocalResourcesEquivalent function to compare two local resources for equivalence. See ResourceSyncerConfig.ResourcesEquivalent // for more details. @@ -74,11 +74,11 @@ type ResourceConfig struct { // BrokerResourceType the type of the broker resources to sync to the local source. BrokerResourceType runtime.Object - // BrokerTransform function used to transform a broker resource to the equivalent local resource. - BrokerTransform syncer.TransformFunc + // TransformBrokerToLocal function used to transform a broker resource to the equivalent local resource. + TransformBrokerToLocal syncer.TransformFunc - // OnSuccessfulSync function invoked after a successful sync operation from the broker. - BrokerOnSuccessfulSync syncer.OnSuccessfulSyncFunc + // OnSuccessfulSyncFromBroker function invoked after a successful sync operation from the broker. + OnSuccessfulSyncFromBroker syncer.OnSuccessfulSyncFunc // BrokerResourcesEquivalent function to compare two broker resources for equivalence. See ResourceSyncerConfig.ResourcesEquivalent // for more details. @@ -211,8 +211,8 @@ func NewSyncer(config SyncerConfig) (*Syncer, error) { //nolint:gocritic // Mini RestMapper: config.RestMapper, Federator: brokerSyncer.remoteFederator, ResourceType: rc.LocalResourceType, - Transform: rc.LocalTransform, - OnSuccessfulSync: rc.LocalOnSuccessfulSync, + Transform: rc.TransformLocalToBroker, + OnSuccessfulSync: rc.OnSuccessfulSyncToBroker, ResourcesEquivalent: rc.LocalResourcesEquivalent, ShouldProcess: rc.LocalShouldProcess, WaitForCacheSync: rc.LocalWaitForCacheSync, @@ -244,8 +244,8 @@ func NewSyncer(config SyncerConfig) (*Syncer, error) { //nolint:gocritic // Mini RestMapper: config.RestMapper, Federator: brokerSyncer.localFederator, ResourceType: rc.BrokerResourceType, - Transform: rc.BrokerTransform, - OnSuccessfulSync: rc.BrokerOnSuccessfulSync, + Transform: rc.TransformBrokerToLocal, + OnSuccessfulSync: rc.OnSuccessfulSyncFromBroker, ResourcesEquivalent: rc.BrokerResourcesEquivalent, WaitForCacheSync: waitForCacheSync, Scheme: config.Scheme, diff --git a/pkg/syncer/broker/syncer_test.go b/pkg/syncer/broker/syncer_test.go index c580d429..eff49bd4 100644 --- a/pkg/syncer/broker/syncer_test.go +++ b/pkg/syncer/broker/syncer_test.go @@ -218,7 +218,7 @@ var _ = Describe("Broker Syncer", func() { When("a local transform function is specified", func() { BeforeEach(func() { transformed = test.NewPodWithImage(config.LocalNamespace, "transformed") - config.ResourceConfigs[0].LocalTransform = func(from runtime.Object, numRequeues int, + config.ResourceConfigs[0].TransformLocalToBroker = func(from runtime.Object, numRequeues int, op sync.Operation, ) (runtime.Object, bool) { return transformed, false @@ -238,7 +238,7 @@ var _ = Describe("Broker Syncer", func() { When("a broker transform function is specified", func() { BeforeEach(func() { transformed = test.NewPodWithImage(config.LocalNamespace, "transformed") - config.ResourceConfigs[0].BrokerTransform = func(from runtime.Object, numRequeues int, + config.ResourceConfigs[0].TransformBrokerToLocal = func(from runtime.Object, numRequeues int, op sync.Operation, ) (runtime.Object, bool) { return transformed, false diff --git a/test/e2e/syncer/broker.go b/test/e2e/syncer/broker.go index 1dfe5cf3..48a2a53f 100644 --- a/test/e2e/syncer/broker.go +++ b/test/e2e/syncer/broker.go @@ -48,7 +48,7 @@ import ( var _ = Describe("[syncer] Broker bi-directional syncer tests", func() { Context("with a specific source namespace", testWithSpecificSourceNamespace) Context("with source namespace all", testWithSourceNamespaceAll) - Context("with local transform", testWithLocalTransform) + Context("with local-to-broker transform", testWithTransformLocalToBroker) Context("with a label selector", testWithLabelSelector) Context("with a field selector", testWithFieldSelector) }) @@ -67,12 +67,12 @@ func testWithSourceNamespaceAll() { newTestDriver().bidirectionalSyncTests() } -func testWithLocalTransform() { +func testWithTransformLocalToBroker() { t := newTestDriver() BeforeEach(func() { t.brokerResourceType = &testV1.ExportedToaster{} - t.localTransform = func(from runtime.Object, numRequeues int, op syncer.Operation) (runtime.Object, bool) { + t.transformLocalToBroker = func(from runtime.Object, numRequeues int, op syncer.Operation) (runtime.Object, bool) { toaster, ok := from.(*testV1.Toaster) Expect(ok).To(BeTrue()) @@ -147,14 +147,14 @@ func testWithFieldSelector() { } type testDriver struct { - framework *framework.Framework - localSourceNamespace string - localTransform func(from runtime.Object, numRequeues int, op syncer.Operation) (runtime.Object, bool) - brokerResourceType runtime.Object - labelSelector string - fieldSelector string - clusterClients []dynamic.Interface - stopCh chan struct{} + framework *framework.Framework + localSourceNamespace string + transformLocalToBroker func(from runtime.Object, numRequeues int, op syncer.Operation) (runtime.Object, bool) + brokerResourceType runtime.Object + labelSelector string + fieldSelector string + clusterClients []dynamic.Interface + stopCh chan struct{} } func newTestDriver() *testDriver { @@ -220,7 +220,7 @@ func (t *testDriver) newSyncer(cluster framework.ClusterIndex) *broker.Syncer { LocalSourceNamespace: t.localSourceNamespace, LocalSourceLabelSelector: t.labelSelector, LocalSourceFieldSelector: t.fieldSelector, - LocalTransform: t.localTransform, + TransformLocalToBroker: t.transformLocalToBroker, BrokerResourceType: t.brokerResourceType, }, },