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

Rename local/broker transformers for clarity #577

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 12 additions & 12 deletions pkg/syncer/broker/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/syncer/broker/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions test/e2e/syncer/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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())

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
},
Expand Down