From 793604a3ce16a20e9153e631aefe0d116b86083e Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Thu, 1 Feb 2024 14:31:54 +0100 Subject: [PATCH] refactor: syncup & syncdown naming --- .../advanced-topics/plugins-development.mdx | 8 ++-- docs/pages/plugins/tutorial.mdx | 2 +- pkg/controllers/generic/export_syncer.go | 6 +-- pkg/controllers/generic/import_syncer.go | 12 +++--- .../resources/configmaps/syncer.go | 2 +- .../resources/configmaps/syncer_test.go | 4 +- .../resources/csidrivers/syncer.go | 6 +-- .../resources/csidrivers/syncer_test.go | 4 +- pkg/controllers/resources/csinodes/syncer.go | 6 +-- .../resources/csinodes/syncer_test.go | 4 +- .../resources/csistoragecapacities/syncer.go | 8 ++-- .../csistoragecapacities/syncer_test.go | 40 +++++++++---------- .../csistoragecapacities/translator.go | 8 ++-- pkg/controllers/resources/endpoints/syncer.go | 4 +- .../resources/endpoints/syncer_test.go | 2 +- pkg/controllers/resources/events/syncer.go | 6 +-- .../resources/ingressclasses/syncer.go | 6 +-- .../resources/ingressclasses/syncer_test.go | 4 +- .../resources/ingresses/legacy/syncer.go | 2 +- .../resources/ingresses/legacy/syncer_test.go | 2 +- pkg/controllers/resources/ingresses/syncer.go | 2 +- .../resources/ingresses/syncer_test.go | 2 +- .../resources/namespaces/syncer.go | 2 +- .../resources/networkpolicies/syncer.go | 2 +- .../resources/networkpolicies/syncer_test.go | 16 ++++---- .../resources/nodes/fake_syncer.go | 2 +- .../resources/nodes/fake_syncer_test.go | 2 +- pkg/controllers/resources/nodes/syncer.go | 10 ++--- .../resources/nodes/syncer_test.go | 4 +- .../persistentvolumeclaims/syncer.go | 2 +- .../persistentvolumeclaims/syncer_test.go | 4 +- .../persistentvolumes/fake_syncer.go | 2 +- .../persistentvolumes/fake_syncer_test.go | 4 +- .../resources/persistentvolumes/syncer.go | 10 ++--- .../persistentvolumes/syncer_test.go | 6 +-- .../resources/poddisruptionbudgets/syncer.go | 2 +- .../poddisruptionbudgets/syncer_test.go | 2 +- pkg/controllers/resources/pods/syncer.go | 2 +- pkg/controllers/resources/pods/syncer_test.go | 12 +++--- .../resources/priorityclasses/syncer.go | 2 +- pkg/controllers/resources/secrets/syncer.go | 2 +- .../resources/secrets/syncer_test.go | 4 +- .../resources/serviceaccounts/syncer.go | 2 +- .../resources/serviceaccounts/syncer_test.go | 2 +- pkg/controllers/resources/services/syncer.go | 6 +-- .../resources/services/syncer_test.go | 2 +- .../storageclasses/host_sc_syncer.go | 6 +-- .../resources/storageclasses/syncer.go | 2 +- .../resources/storageclasses/syncer_test.go | 2 +- .../volumesnapshotclasses/syncer.go | 6 +-- .../volumesnapshotclasses/syncer_test.go | 4 +- .../volumesnapshotcontents/syncer.go | 10 ++--- .../volumesnapshotcontents/syncer_test.go | 6 +-- .../volumesnapshots/volumesnapshots/syncer.go | 2 +- .../volumesnapshots/syncer_test.go | 4 +- pkg/controllers/syncer/fake_syncer.go | 2 +- pkg/controllers/syncer/syncer.go | 18 ++++----- pkg/controllers/syncer/syncer_test.go | 2 +- .../syncer/translator/cluster_translator.go | 4 +- .../translator/mirror_name_translator.go | 4 +- .../translator/namespaced_translator.go | 6 +-- .../syncer/translator/translator.go | 10 ++--- pkg/types/types.go | 12 +++--- 63 files changed, 172 insertions(+), 172 deletions(-) diff --git a/docs/pages/advanced-topics/plugins-development.mdx b/docs/pages/advanced-topics/plugins-development.mdx index 0da758e04..e2ac7fb6a 100644 --- a/docs/pages/advanced-topics/plugins-development.mdx +++ b/docs/pages/advanced-topics/plugins-development.mdx @@ -40,7 +40,7 @@ func main() { Let's break down what is happening in the `main()` function above. -`ctx := plugin.MustInit("sync-all-configmaps-plugin")` - SDK will contact the vCluster backend server and retrieve it's configuration. The returned struct of type [`RegisterContext`](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/syncer/context#RegisterContext) contains information about vCluster flags, namespace, vCluster client config, controller manager objects, etc. +`ctx := plugin.MustInit("sync-all-configmaps-plugin")` - SDK will contact the vCluster backend server and retrieve it's configuration. The returned struct of type [`RegisterContext`](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/syncer/context#RegisterContext) contains information about vCluster flags, namespace, vCluster client config, controller manager objects, etc. `plugin.MustRegister(syncers.NewConfigMapSyncer(ctx))` - we will implement the `NewConfigMapSyncer` function below, but for now, all we need to know is that it should return a struct that implements [`Base`](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/syncer#Base) interface, which is accepted by the [`MustRegister`](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/plugin#MustRegister) function. We should call [`MustRegister`](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/plugin#MustRegister) function for each syncer that we wish to be managed by the plugins controller manager. @@ -77,7 +77,7 @@ type configMapSyncer struct { After an import block, we see the `NewConfigMapSyncer` function, which is being called from the `main.go`. It returns a new instance of the `configMapSyncer` struct, which is defined by a single nested anonymous struct of type [`NamespacedTranslator`](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/syncer/translator#NamespacedTranslator). The [`NamespacedTranslator`](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/syncer/translator#NamespacedTranslator) implements many functions of the [`Syncer`](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/syncer#Syncer) interface for us, and we will implement the remaining ones - `SyncDown` and `Sync`. -:::info +:::info You can get more familiar with the interfaces mentioned above by reading the SDK source files on GitHub - [vcluster-sdk/syncer/types.go](https://github.com/loft-sh/vcluster-sdk/blob/main/syncer/types.go) and [vcluster-sdk/syncer/translator/translator.go](https://github.com/loft-sh/vcluster-sdk/blob/main/syncer/translator/translator.go), or by using pkg.go.dev website - [Syncer](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/syncer#Syncer) and [NamespacedTranslator](https://pkg.go.dev/github.com/loft-sh/vcluster-sdk/syncer/translator#NamespacedTranslator). ::: @@ -85,7 +85,7 @@ You can get more familiar with the interfaces mentioned above by reading the SDK The `SyncDown` function mentioned above is called by the vCluster SDK when a given resource, e.g. a ConfigMap, is created in the vCluster, but it doesn't exist in the host cluster yet. To create a ConfigMap in the host cluster we will call the `SyncDownCreate` function with the output of the `translate` function as a third parameter. This demonstrates a typical pattern used in the vCluster syncer implementations. ``` -func (s *configMapSyncer) SyncDown(ctx *syncercontext.syncercontext, vObj client.Object) (ctrl.Result, error) { +func (s *configMapSyncer) SyncToHost(ctx *syncercontext.syncercontext, vObj client.Object) (ctrl.Result, error) { return s.SyncDownCreate(ctx, vObj, s.translate(vObj.(*corev1.ConfigMap))) } @@ -298,7 +298,7 @@ You can now change a file locally in your IDE and then restart the command in th DevSpace will create a development vCluster which will execute your plugin. Any changes made within the vCluster created by DevSpace will execute against your plugin. ``` -vcluster list +vcluster list NAME NAMESPACE STATUS CONNECTED CREATED AGE vcluster vcluster Running True 2022-09-06 20:33:20 +1000 AEST 2h26m8s diff --git a/docs/pages/plugins/tutorial.mdx b/docs/pages/plugins/tutorial.mdx index 411d68a76..7a97b41f6 100644 --- a/docs/pages/plugins/tutorial.mdx +++ b/docs/pages/plugins/tutorial.mdx @@ -93,7 +93,7 @@ After an import block, we see the `NewCarSyncer` function, which is being called The `SyncDown` function mentioned above is called by the vCluster SDK when a given resource, e.g. a Car, is created in the vCluster, but it doesn't exist in the host cluster yet. To create a ConfigMap in the host cluster we will call the `SyncDownCreate` function with the output of the `translate` function as third parameter. This demonstrates a typical pattern used in the vCluster syncer implementations. ``` -func (s *carSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *carSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { return s.SyncDownCreate(ctx, vObj, s.TranslateMetadata(ctx.Context, vObj).(*examplev1.Car)) } diff --git a/pkg/controllers/generic/export_syncer.go b/pkg/controllers/generic/export_syncer.go index c684b49ed..cb167730f 100644 --- a/pkg/controllers/generic/export_syncer.go +++ b/pkg/controllers/generic/export_syncer.go @@ -132,7 +132,7 @@ type exporter struct { name string } -func (f *exporter) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (f *exporter) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { // check if selector matches if !f.objectMatches(vObj) { return ctrl.Result{}, nil @@ -261,9 +261,9 @@ func (f *exporter) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj c return ctrl.Result{}, nil } -var _ syncertypes.UpSyncer = &exporter{} +var _ syncertypes.ToVirtualSyncer = &exporter{} -func (f *exporter) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (f *exporter) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { if !translate.Default.IsManaged(pObj) { return ctrl.Result{}, nil } diff --git a/pkg/controllers/generic/import_syncer.go b/pkg/controllers/generic/import_syncer.go index 6c76943cd..e20de6373 100644 --- a/pkg/controllers/generic/import_syncer.go +++ b/pkg/controllers/generic/import_syncer.go @@ -177,9 +177,9 @@ func (s *importer) excludeObject(obj client.Object) bool { return false } -var _ syncertypes.UpSyncer = &importer{} +var _ syncertypes.ToVirtualSyncer = &importer{} -func (s *importer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *importer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { // check if annotation is already present if pObj.GetAnnotations() != nil { if pObj.GetAnnotations()[translate.ControllerLabel] == s.Name() && @@ -234,7 +234,7 @@ func (s *importer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctr var _ syncertypes.Syncer = &importer{} -func (s *importer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *importer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { // ignore all virtual resources that were not created by this controller if !s.IsVirtualManaged(vObj) { return ctrl.Result{}, nil @@ -354,11 +354,11 @@ func (s *importer) IsVirtualManaged(vObj client.Object) bool { return vObj.GetAnnotations() != nil && vObj.GetAnnotations()[translate.ControllerLabel] != "" && vObj.GetAnnotations()[translate.ControllerLabel] == s.Name() } -func (s *importer) VirtualToPhysical(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { +func (s *importer) VirtualToHost(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { return types.NamespacedName{Name: translate.Default.PhysicalName(req.Name, req.Namespace), Namespace: translate.Default.PhysicalNamespace(req.Namespace)} } -func (s *importer) PhysicalToVirtual(ctx context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { +func (s *importer) HostToVirtual(ctx context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { if s.syncerOptions.IsClusterScopedCRD { return types.NamespacedName{ Name: req.Name, @@ -382,7 +382,7 @@ func (s *importer) TranslateMetadata(ctx context.Context, pObj client.Object) cl vObj.SetOwnerReferences(nil) vObj.SetFinalizers(nil) vObj.SetAnnotations(s.updateVirtualAnnotations(vObj.GetAnnotations())) - nn := s.PhysicalToVirtual(ctx, types.NamespacedName{Name: pObj.GetName(), Namespace: pObj.GetNamespace()}, pObj) + nn := s.HostToVirtual(ctx, types.NamespacedName{Name: pObj.GetName(), Namespace: pObj.GetNamespace()}, pObj) vObj.SetName(nn.Name) vObj.SetNamespace(nn.Namespace) diff --git a/pkg/controllers/resources/configmaps/syncer.go b/pkg/controllers/resources/configmaps/syncer.go index 735234991..14df795d8 100644 --- a/pkg/controllers/resources/configmaps/syncer.go +++ b/pkg/controllers/resources/configmaps/syncer.go @@ -66,7 +66,7 @@ func (s *configMapSyncer) ModifyController(_ *synccontext.RegisterContext, build return builder.Watches(&corev1.Pod{}, handler.EnqueueRequestsFromMapFunc(mapPods)), nil } -func (s *configMapSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *configMapSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { createNeeded, err := s.isConfigMapUsed(ctx, vObj) if err != nil { return ctrl.Result{}, err diff --git a/pkg/controllers/resources/configmaps/syncer_test.go b/pkg/controllers/resources/configmaps/syncer_test.go index 8cf754f05..1e4f97211 100644 --- a/pkg/controllers/resources/configmaps/syncer_test.go +++ b/pkg/controllers/resources/configmaps/syncer_test.go @@ -77,7 +77,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*configMapSyncer).SyncDown(syncCtx, baseConfigMap) + _, err := syncer.(*configMapSyncer).SyncToHost(syncCtx, baseConfigMap) assert.NilError(t, err) }, }, @@ -94,7 +94,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*configMapSyncer).SyncDown(syncCtx, baseConfigMap) + _, err := syncer.(*configMapSyncer).SyncToHost(syncCtx, baseConfigMap) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/csidrivers/syncer.go b/pkg/controllers/resources/csidrivers/syncer.go index 8058bd767..4ddd570a0 100644 --- a/pkg/controllers/resources/csidrivers/syncer.go +++ b/pkg/controllers/resources/csidrivers/syncer.go @@ -19,10 +19,10 @@ type csidriverSyncer struct { translator.Translator } -var _ syncer.UpSyncer = &csidriverSyncer{} +var _ syncer.ToVirtualSyncer = &csidriverSyncer{} var _ syncer.Syncer = &csidriverSyncer{} -func (s *csidriverSyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *csidriverSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { vObj := s.translateBackwards(ctx.Context, pObj.(*storagev1.CSIDriver)) ctx.Log.Infof("create CSIDriver %s, because it does not exist in virtual cluster", vObj.Name) return ctrl.Result{}, ctx.VirtualClient.Create(ctx.Context, vObj) @@ -40,7 +40,7 @@ func (s *csidriverSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, return ctrl.Result{}, nil } -func (s *csidriverSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *csidriverSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { ctx.Log.Infof("delete virtual CSIDriver %s, because physical object is missing", vObj.GetName()) return ctrl.Result{}, ctx.VirtualClient.Delete(ctx.Context, vObj) } diff --git a/pkg/controllers/resources/csidrivers/syncer_test.go b/pkg/controllers/resources/csidrivers/syncer_test.go index 6d6242c4b..e0076de02 100644 --- a/pkg/controllers/resources/csidrivers/syncer_test.go +++ b/pkg/controllers/resources/csidrivers/syncer_test.go @@ -104,7 +104,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*csidriverSyncer).SyncUp(syncCtx, pObj) + _, err := syncer.(*csidriverSyncer).SyncToVirtual(syncCtx, pObj) assert.NilError(t, err) }, }, @@ -115,7 +115,7 @@ func TestSync(t *testing.T) { ExpectedPhysicalState: map[schema.GroupVersionKind][]runtime.Object{}, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*csidriverSyncer).SyncDown(syncCtx, vObj) + _, err := syncer.(*csidriverSyncer).SyncToHost(syncCtx, vObj) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/csinodes/syncer.go b/pkg/controllers/resources/csinodes/syncer.go index d35e06c9c..111f06d16 100644 --- a/pkg/controllers/resources/csinodes/syncer.go +++ b/pkg/controllers/resources/csinodes/syncer.go @@ -24,10 +24,10 @@ type csinodeSyncer struct { virtualClient client.Client } -var _ syncertypes.UpSyncer = &csinodeSyncer{} +var _ syncertypes.ToVirtualSyncer = &csinodeSyncer{} var _ syncertypes.Syncer = &csinodeSyncer{} -func (s *csinodeSyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *csinodeSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { // look up matching node name, don't sync if not found node := &corev1.Node{} err := s.virtualClient.Get(ctx.Context, types.NamespacedName{Name: pObj.GetName()}, node) @@ -62,7 +62,7 @@ func (s *csinodeSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, v return ctrl.Result{}, nil } -func (s *csinodeSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *csinodeSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { ctx.Log.Infof("delete virtual CSINode %s, because physical object is missing", vObj.GetName()) return ctrl.Result{}, ctx.VirtualClient.Delete(ctx.Context, vObj) } diff --git a/pkg/controllers/resources/csinodes/syncer_test.go b/pkg/controllers/resources/csinodes/syncer_test.go index c4f496aa4..7a7e6aa12 100644 --- a/pkg/controllers/resources/csinodes/syncer_test.go +++ b/pkg/controllers/resources/csinodes/syncer_test.go @@ -107,7 +107,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*csinodeSyncer).SyncUp(syncCtx, pObj) + _, err := syncer.(*csinodeSyncer).SyncToVirtual(syncCtx, pObj) assert.NilError(t, err) }, }, @@ -118,7 +118,7 @@ func TestSync(t *testing.T) { ExpectedPhysicalState: map[schema.GroupVersionKind][]runtime.Object{}, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*csinodeSyncer).SyncDown(syncCtx, vObj) + _, err := syncer.(*csinodeSyncer).SyncToHost(syncCtx, vObj) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/csistoragecapacities/syncer.go b/pkg/controllers/resources/csistoragecapacities/syncer.go index 335d81b43..6255b66b1 100644 --- a/pkg/controllers/resources/csistoragecapacities/syncer.go +++ b/pkg/controllers/resources/csistoragecapacities/syncer.go @@ -34,10 +34,10 @@ type csistoragecapacitySyncer struct { physicalClient client.Client } -var _ syncertypes.UpSyncer = &csistoragecapacitySyncer{} +var _ syncertypes.ToVirtualSyncer = &csistoragecapacitySyncer{} var _ syncertypes.Syncer = &csistoragecapacitySyncer{} -func (s *csistoragecapacitySyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *csistoragecapacitySyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { vObj, shouldSkip, err := s.translateBackwards(ctx, pObj.(*storagev1.CSIStorageCapacity)) if err != nil || shouldSkip { return ctrl.Result{}, err @@ -67,7 +67,7 @@ func (s *csistoragecapacitySyncer) Sync(ctx *synccontext.SyncContext, pObj clien return ctrl.Result{}, nil } -func (s *csistoragecapacitySyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *csistoragecapacitySyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { ctx.Log.Infof("delete virtual CSIStorageCapacity %s, because physical object is missing", vObj.GetName()) return ctrl.Result{}, ctx.VirtualClient.Delete(ctx.Context, vObj) } @@ -109,7 +109,7 @@ func (s *csistoragecapacitySyncer) enqueuePhysical(ctx context.Context, obj clie return } - name := s.PhysicalToVirtual(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, obj) + name := s.HostToVirtual(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, obj) if name.Name != "" && name.Namespace != "" { q.Add(reconcile.Request{NamespacedName: name}) } diff --git a/pkg/controllers/resources/csistoragecapacities/syncer_test.go b/pkg/controllers/resources/csistoragecapacities/syncer_test.go index 92b36d492..b7fef3e4e 100644 --- a/pkg/controllers/resources/csistoragecapacities/syncer_test.go +++ b/pkg/controllers/resources/csistoragecapacities/syncer_test.go @@ -106,7 +106,7 @@ func TestSyncHostStorageClass(t *testing.T) { ctx.Controllers.Insert("hoststorageclasses") ctx.Controllers.Delete("storageclasses") syncCtx, sync := generictesting.FakeStartSyncer(t, ctx, New) - _, err := sync.(*csistoragecapacitySyncer).SyncUp(syncCtx, pObj) + _, err := sync.(*csistoragecapacitySyncer).SyncToVirtual(syncCtx, pObj) assert.NilError(t, err) }, }, @@ -119,7 +119,7 @@ func TestSyncHostStorageClass(t *testing.T) { ctx.Controllers.Insert("hoststorageclasses") ctx.Controllers.Delete("storageclasses") syncCtx, sync := generictesting.FakeStartSyncer(t, ctx, New) - _, err := sync.(*csistoragecapacitySyncer).SyncDown(syncCtx, vObj) + _, err := sync.(*csistoragecapacitySyncer).SyncToHost(syncCtx, vObj) assert.NilError(t, err) }, }, @@ -246,13 +246,13 @@ func TestSyncStorageClass(t *testing.T) { ctx.Controllers.Insert("storageclasses") var err error syncCtx, sync := generictesting.FakeStartSyncer(t, ctx, storageclasses.New) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCa) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCa) assert.NilError(t, err) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCb) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCb) assert.NilError(t, err) syncCtx, sync = generictesting.FakeStartSyncer(t, ctx, New) - _, err = sync.(*csistoragecapacitySyncer).SyncUp(syncCtx, pObj) + _, err = sync.(*csistoragecapacitySyncer).SyncToVirtual(syncCtx, pObj) assert.NilError(t, err) }, }, @@ -271,13 +271,13 @@ func TestSyncStorageClass(t *testing.T) { ctx.Controllers.Insert("storageclasses") var err error syncCtx, sync := generictesting.FakeStartSyncer(t, ctx, storageclasses.New) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCa) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCa) assert.NilError(t, err) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCb) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCb) assert.NilError(t, err) syncCtx, sync = generictesting.FakeStartSyncer(t, ctx, New) - _, err = sync.(*csistoragecapacitySyncer).SyncUp(syncCtx, pObj) + _, err = sync.(*csistoragecapacitySyncer).SyncToVirtual(syncCtx, pObj) assert.NilError(t, err) }, }, @@ -296,13 +296,13 @@ func TestSyncStorageClass(t *testing.T) { ctx.Controllers.Insert("storageclasses") var err error syncCtx, sync := generictesting.FakeStartSyncer(t, ctx, storageclasses.New) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCa) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCa) assert.NilError(t, err) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCb) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCb) assert.NilError(t, err) syncCtx, sync = generictesting.FakeStartSyncer(t, ctx, New) - _, err = sync.(*csistoragecapacitySyncer).SyncUp(syncCtx, pObj) + _, err = sync.(*csistoragecapacitySyncer).SyncToVirtual(syncCtx, pObj) assert.NilError(t, err) }, }, @@ -316,13 +316,13 @@ func TestSyncStorageClass(t *testing.T) { ctx.Controllers.Insert("storageclasses") var err error syncCtx, sync := generictesting.FakeStartSyncer(t, ctx, storageclasses.New) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCa) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCa) assert.NilError(t, err) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCb) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCb) assert.NilError(t, err) syncCtx, sync = generictesting.FakeStartSyncer(t, ctx, New) - _, err = sync.(*csistoragecapacitySyncer).SyncDown(syncCtx, vObj) + _, err = sync.(*csistoragecapacitySyncer).SyncToHost(syncCtx, vObj) assert.NilError(t, err) }, }, @@ -341,9 +341,9 @@ func TestSyncStorageClass(t *testing.T) { ctx.Controllers.Insert("storageclasses") var err error syncCtx, sync := generictesting.FakeStartSyncer(t, ctx, storageclasses.New) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCa) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCa) assert.NilError(t, err) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCb) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCb) assert.NilError(t, err) syncCtx, sync = generictesting.FakeStartSyncer(t, ctx, New) @@ -366,9 +366,9 @@ func TestSyncStorageClass(t *testing.T) { ctx.Controllers.Insert("storageclasses") var err error syncCtx, sync := generictesting.FakeStartSyncer(t, ctx, storageclasses.New) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCa) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCa) assert.NilError(t, err) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCb) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCb) assert.NilError(t, err) syncCtx, sync = generictesting.FakeStartSyncer(t, ctx, New) @@ -391,9 +391,9 @@ func TestSyncStorageClass(t *testing.T) { ctx.Controllers.Insert("storageclasses") var err error syncCtx, sync := generictesting.FakeStartSyncer(t, ctx, storageclasses.New) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCa) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCa) assert.NilError(t, err) - _, err = sync.(syncer.Syncer).SyncDown(syncCtx, vSCb) + _, err = sync.(syncer.Syncer).SyncToHost(syncCtx, vSCb) assert.NilError(t, err) syncCtx, sync = generictesting.FakeStartSyncer(t, ctx, New) diff --git a/pkg/controllers/resources/csistoragecapacities/translator.go b/pkg/controllers/resources/csistoragecapacities/translator.go index 02c4844aa..8ab343cdf 100644 --- a/pkg/controllers/resources/csistoragecapacities/translator.go +++ b/pkg/controllers/resources/csistoragecapacities/translator.go @@ -31,15 +31,15 @@ func (s *csistoragecapacitySyncer) IsManaged(context.Context, client.Object) (bo func (s *csistoragecapacitySyncer) RegisterIndices(ctx *synccontext.RegisterContext) error { return ctx.PhysicalManager.GetFieldIndexer().IndexField(ctx.Context, &storagev1.CSIStorageCapacity{}, constants.IndexByVirtualName, func(rawObj client.Object) []string { - return []string{s.PhysicalToVirtual(ctx.Context, types.NamespacedName{Name: rawObj.GetName(), Namespace: rawObj.GetNamespace()}, rawObj).Name} + return []string{s.HostToVirtual(ctx.Context, types.NamespacedName{Name: rawObj.GetName(), Namespace: rawObj.GetNamespace()}, rawObj).Name} }) } // translate namespace -func (s *csistoragecapacitySyncer) PhysicalToVirtual(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { +func (s *csistoragecapacitySyncer) HostToVirtual(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { return types.NamespacedName{Name: translate.SafeConcatName(req.Name, "x", req.Namespace), Namespace: "kube-system"} } -func (s *csistoragecapacitySyncer) VirtualToPhysical(ctx context.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { +func (s *csistoragecapacitySyncer) VirtualToHost(ctx context.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { // if the virtual object is annotated with the physical name and namespace, return that if vObj != nil { vAnnotations := vObj.GetAnnotations() @@ -66,7 +66,7 @@ func (s *csistoragecapacitySyncer) VirtualToPhysical(ctx context.Context, req ty // TranslateMetadata translates the object's metadata func (s *csistoragecapacitySyncer) TranslateMetadata(ctx context.Context, pObj client.Object) (client.Object, error) { - name := s.PhysicalToVirtual(ctx, types.NamespacedName{Name: pObj.GetName(), Namespace: pObj.GetNamespace()}, pObj) + name := s.HostToVirtual(ctx, types.NamespacedName{Name: pObj.GetName(), Namespace: pObj.GetNamespace()}, pObj) pObjCopy := pObj.DeepCopyObject() vObj, ok := pObjCopy.(client.Object) if !ok { diff --git a/pkg/controllers/resources/endpoints/syncer.go b/pkg/controllers/resources/endpoints/syncer.go index 1062d967b..9b6db75b3 100644 --- a/pkg/controllers/resources/endpoints/syncer.go +++ b/pkg/controllers/resources/endpoints/syncer.go @@ -24,7 +24,7 @@ type endpointsSyncer struct { translator.NamespacedTranslator } -func (s *endpointsSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *endpointsSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { return s.SyncDownCreate(ctx, vObj, s.translate(ctx.Context, vObj)) } @@ -60,7 +60,7 @@ func (s *endpointsSyncer) ReconcileStart(ctx *synccontext.SyncContext, req ctrl. } else if svc.Spec.Selector != nil { // check if it was a managed endpoints object before and delete it endpoints := &corev1.Endpoints{} - err := ctx.PhysicalClient.Get(ctx.Context, s.NamespacedTranslator.VirtualToPhysical(ctx.Context, req.NamespacedName, nil), endpoints) + err := ctx.PhysicalClient.Get(ctx.Context, s.NamespacedTranslator.VirtualToHost(ctx.Context, req.NamespacedName, nil), endpoints) if err != nil { if !kerrors.IsNotFound(err) { klog.Infof("Error retrieving endpoints: %v", err) diff --git a/pkg/controllers/resources/endpoints/syncer_test.go b/pkg/controllers/resources/endpoints/syncer_test.go index 00aaf4a67..a8cf31ed1 100644 --- a/pkg/controllers/resources/endpoints/syncer_test.go +++ b/pkg/controllers/resources/endpoints/syncer_test.go @@ -77,7 +77,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*endpointsSyncer).SyncDown(syncCtx, baseEndpoints) + _, err := syncer.(*endpointsSyncer).SyncToHost(syncCtx, baseEndpoints) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/events/syncer.go b/pkg/controllers/resources/events/syncer.go index daf627dbe..ae2a42bfd 100644 --- a/pkg/controllers/resources/events/syncer.go +++ b/pkg/controllers/resources/events/syncer.go @@ -52,11 +52,11 @@ func (s *eventSyncer) IsManaged(context.Context, client.Object) (bool, error) { return true, nil } -func (s *eventSyncer) VirtualToPhysical(context.Context, types.NamespacedName, client.Object) types.NamespacedName { +func (s *eventSyncer) VirtualToHost(context.Context, types.NamespacedName, client.Object) types.NamespacedName { return types.NamespacedName{} } -func (s *eventSyncer) PhysicalToVirtual(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { +func (s *eventSyncer) HostToVirtual(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { return req } @@ -189,7 +189,7 @@ func (s *eventSyncer) reconcile(ctx *synccontext.SyncContext, req ctrl.Request) var _ syncer.Syncer = &eventSyncer{} -func (s *eventSyncer) SyncDown(*synccontext.SyncContext, client.Object) (ctrl.Result, error) { +func (s *eventSyncer) SyncToHost(*synccontext.SyncContext, client.Object) (ctrl.Result, error) { // Noop, we do nothing here return ctrl.Result{}, nil } diff --git a/pkg/controllers/resources/ingressclasses/syncer.go b/pkg/controllers/resources/ingressclasses/syncer.go index e9a453947..2804027d9 100644 --- a/pkg/controllers/resources/ingressclasses/syncer.go +++ b/pkg/controllers/resources/ingressclasses/syncer.go @@ -19,10 +19,10 @@ type ingressClassSyncer struct { translator.Translator } -var _ syncer.UpSyncer = &ingressClassSyncer{} +var _ syncer.ToVirtualSyncer = &ingressClassSyncer{} var _ syncer.Syncer = &ingressClassSyncer{} -func (i *ingressClassSyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (i *ingressClassSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { vObj := i.translateBackwards(ctx.Context, pObj.(*networkingv1.IngressClass)) ctx.Log.Infof("create ingress class %s, because it does not exist in virtual cluster", vObj.Name) return ctrl.Result{}, ctx.VirtualClient.Create(ctx.Context, vObj) @@ -39,7 +39,7 @@ func (i *ingressClassSyncer) Sync(ctx *synccontext.SyncContext, pObj, vObj clien return ctrl.Result{}, nil } -func (i *ingressClassSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (i *ingressClassSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { ctx.Log.Infof("delete virtual ingress class %s, because physical object is missing", vObj.GetName()) return ctrl.Result{}, ctx.VirtualClient.Delete(ctx.Context, vObj) } diff --git a/pkg/controllers/resources/ingressclasses/syncer_test.go b/pkg/controllers/resources/ingressclasses/syncer_test.go index 990bc8224..24925dc0e 100644 --- a/pkg/controllers/resources/ingressclasses/syncer_test.go +++ b/pkg/controllers/resources/ingressclasses/syncer_test.go @@ -92,7 +92,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*ingressClassSyncer).SyncUp(syncCtx, pObj) + _, err := syncer.(*ingressClassSyncer).SyncToVirtual(syncCtx, pObj) assert.NilError(t, err) }, }, @@ -103,7 +103,7 @@ func TestSync(t *testing.T) { ExpectedPhysicalState: map[schema.GroupVersionKind][]runtime.Object{}, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*ingressClassSyncer).SyncDown(syncCtx, vObj) + _, err := syncer.(*ingressClassSyncer).SyncToHost(syncCtx, vObj) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/ingresses/legacy/syncer.go b/pkg/controllers/resources/ingresses/legacy/syncer.go index 7e81a09b3..0c45eba6f 100644 --- a/pkg/controllers/resources/ingresses/legacy/syncer.go +++ b/pkg/controllers/resources/ingresses/legacy/syncer.go @@ -23,7 +23,7 @@ type ingressSyncer struct { var _ syncertypes.Syncer = &ingressSyncer{} -func (s *ingressSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *ingressSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { return s.SyncDownCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*networkingv1beta1.Ingress))) } diff --git a/pkg/controllers/resources/ingresses/legacy/syncer_test.go b/pkg/controllers/resources/ingresses/legacy/syncer_test.go index 28bb8d20d..a4b8f8a27 100644 --- a/pkg/controllers/resources/ingresses/legacy/syncer_test.go +++ b/pkg/controllers/resources/ingresses/legacy/syncer_test.go @@ -160,7 +160,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, NewSyncer) - _, err := syncer.(*ingressSyncer).SyncDown(syncCtx, baseIngress.DeepCopy()) + _, err := syncer.(*ingressSyncer).SyncToHost(syncCtx, baseIngress.DeepCopy()) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/ingresses/syncer.go b/pkg/controllers/resources/ingresses/syncer.go index 8cf8cc5ec..278ab2b95 100644 --- a/pkg/controllers/resources/ingresses/syncer.go +++ b/pkg/controllers/resources/ingresses/syncer.go @@ -25,7 +25,7 @@ type ingressSyncer struct { var _ syncertypes.Syncer = &ingressSyncer{} -func (s *ingressSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *ingressSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { return s.SyncDownCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*networkingv1.Ingress))) } diff --git a/pkg/controllers/resources/ingresses/syncer_test.go b/pkg/controllers/resources/ingresses/syncer_test.go index ebb39776a..ad52f0b37 100644 --- a/pkg/controllers/resources/ingresses/syncer_test.go +++ b/pkg/controllers/resources/ingresses/syncer_test.go @@ -168,7 +168,7 @@ func TestSync(t *testing.T) { }, Sync: func(registerContext *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, registerContext, NewSyncer) - _, err := syncer.(*ingressSyncer).SyncDown(syncCtx, baseIngress.DeepCopy()) + _, err := syncer.(*ingressSyncer).SyncToHost(syncCtx, baseIngress.DeepCopy()) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/namespaces/syncer.go b/pkg/controllers/resources/namespaces/syncer.go index 34c67f1bd..c38f8fa3c 100644 --- a/pkg/controllers/resources/namespaces/syncer.go +++ b/pkg/controllers/resources/namespaces/syncer.go @@ -62,7 +62,7 @@ func (s *namespaceSyncer) RegisterIndices(ctx *synccontext.RegisterContext) erro var _ syncertypes.Syncer = &namespaceSyncer{} -func (s *namespaceSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *namespaceSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { newNamespace := s.translate(ctx.Context, vObj.(*corev1.Namespace)) ctx.Log.Infof("create physical namespace %s", newNamespace.Name) err := ctx.PhysicalClient.Create(ctx.Context, newNamespace) diff --git a/pkg/controllers/resources/networkpolicies/syncer.go b/pkg/controllers/resources/networkpolicies/syncer.go index a38998444..15858ae99 100644 --- a/pkg/controllers/resources/networkpolicies/syncer.go +++ b/pkg/controllers/resources/networkpolicies/syncer.go @@ -22,7 +22,7 @@ type networkPolicySyncer struct { var _ syncertypes.Syncer = &networkPolicySyncer{} -func (s *networkPolicySyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *networkPolicySyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { return s.SyncDownCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*networkingv1.NetworkPolicy))) } diff --git a/pkg/controllers/resources/networkpolicies/syncer_test.go b/pkg/controllers/resources/networkpolicies/syncer_test.go index 4d775df83..3ee247ff1 100644 --- a/pkg/controllers/resources/networkpolicies/syncer_test.go +++ b/pkg/controllers/resources/networkpolicies/syncer_test.go @@ -227,7 +227,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*networkPolicySyncer).SyncDown(syncCtx, vBaseNetworkPolicy.DeepCopy()) + _, err := syncer.(*networkPolicySyncer).SyncToHost(syncCtx, vBaseNetworkPolicy.DeepCopy()) assert.NilError(t, err) }, }, @@ -242,7 +242,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*networkPolicySyncer).SyncDown(syncCtx, vnetworkPolicyNoPodSelector.DeepCopy()) + _, err := syncer.(*networkPolicySyncer).SyncToHost(syncCtx, vnetworkPolicyNoPodSelector.DeepCopy()) assert.NilError(t, err) }, }, @@ -310,7 +310,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*networkPolicySyncer).SyncDown(syncCtx, vnetworkPolicyWithIPBlock.DeepCopy()) + _, err := syncer.(*networkPolicySyncer).SyncToHost(syncCtx, vnetworkPolicyWithIPBlock.DeepCopy()) assert.NilError(t, err) }, }, @@ -325,7 +325,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*networkPolicySyncer).SyncDown(syncCtx, vnetworkPolicyWithPodSelectorNoNs.DeepCopy()) + _, err := syncer.(*networkPolicySyncer).SyncToHost(syncCtx, vnetworkPolicyWithPodSelectorNoNs.DeepCopy()) assert.NilError(t, err) }, }, @@ -340,7 +340,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*networkPolicySyncer).SyncDown(syncCtx, vnetworkPolicyWithPodSelectorEmptyNs.DeepCopy()) + _, err := syncer.(*networkPolicySyncer).SyncToHost(syncCtx, vnetworkPolicyWithPodSelectorEmptyNs.DeepCopy()) assert.NilError(t, err) }, }, @@ -355,7 +355,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*networkPolicySyncer).SyncDown(syncCtx, vnetworkPolicyWithPodSelectorNsSelector.DeepCopy()) + _, err := syncer.(*networkPolicySyncer).SyncToHost(syncCtx, vnetworkPolicyWithPodSelectorNsSelector.DeepCopy()) assert.NilError(t, err) }, }, @@ -370,7 +370,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*networkPolicySyncer).SyncDown(syncCtx, vnetworkPolicyWithMatchExpressions.DeepCopy()) + _, err := syncer.(*networkPolicySyncer).SyncToHost(syncCtx, vnetworkPolicyWithMatchExpressions.DeepCopy()) assert.NilError(t, err) }, }, @@ -385,7 +385,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*networkPolicySyncer).SyncDown(syncCtx, vnetworkPolicyEgressWithPodSelectorNoNs.DeepCopy()) + _, err := syncer.(*networkPolicySyncer).SyncToHost(syncCtx, vnetworkPolicyEgressWithPodSelectorNoNs.DeepCopy()) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/nodes/fake_syncer.go b/pkg/controllers/resources/nodes/fake_syncer.go index 38cb6c33f..8ee8321fe 100644 --- a/pkg/controllers/resources/nodes/fake_syncer.go +++ b/pkg/controllers/resources/nodes/fake_syncer.go @@ -65,7 +65,7 @@ func (r *fakeNodeSyncer) ModifyController(ctx *synccontext.RegisterContext, buil var _ syncer.FakeSyncer = &fakeNodeSyncer{} -func (r *fakeNodeSyncer) FakeSyncUp(ctx *synccontext.SyncContext, name types.NamespacedName) (ctrl.Result, error) { +func (r *fakeNodeSyncer) FakeSyncToVirtual(ctx *synccontext.SyncContext, name types.NamespacedName) (ctrl.Result, error) { needed, err := r.nodeNeeded(ctx, name.Name) if err != nil { return ctrl.Result{}, err diff --git a/pkg/controllers/resources/nodes/fake_syncer_test.go b/pkg/controllers/resources/nodes/fake_syncer_test.go index 6b400528b..c8ca0db6e 100644 --- a/pkg/controllers/resources/nodes/fake_syncer_test.go +++ b/pkg/controllers/resources/nodes/fake_syncer_test.go @@ -151,7 +151,7 @@ func TestFakeSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncContext, syncer := newFakeFakeSyncer(t, ctx) - _, err := syncer.FakeSyncUp(syncContext, baseName) + _, err := syncer.FakeSyncToVirtual(syncContext, baseName) assert.NilError(t, err) }, Compare: func(obj1 runtime.Object, obj2 runtime.Object) bool { diff --git a/pkg/controllers/resources/nodes/syncer.go b/pkg/controllers/resources/nodes/syncer.go index fd882c9f9..63fecd7e5 100644 --- a/pkg/controllers/resources/nodes/syncer.go +++ b/pkg/controllers/resources/nodes/syncer.go @@ -251,11 +251,11 @@ func registerIndices(ctx *synccontext.RegisterContext) error { }) } -func (s *nodeSyncer) VirtualToPhysical(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { +func (s *nodeSyncer) VirtualToHost(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { return req } -func (s *nodeSyncer) PhysicalToVirtual(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { +func (s *nodeSyncer) HostToVirtual(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { return types.NamespacedName{Name: req.Name} } @@ -270,7 +270,7 @@ func (s *nodeSyncer) IsManaged(ctx context.Context, pObj client.Object) (bool, e var _ syncertypes.Syncer = &nodeSyncer{} -func (s *nodeSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *nodeSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { vNode := vObj.(*corev1.Node) ctx.Log.Infof("delete virtual node %s, because it is not needed anymore", vNode.Name) return ctrl.Result{}, ctx.VirtualClient.Delete(ctx.Context, vObj) @@ -314,9 +314,9 @@ func (s *nodeSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj return ctrl.Result{}, nil } -var _ syncertypes.UpSyncer = &nodeSyncer{} +var _ syncertypes.ToVirtualSyncer = &nodeSyncer{} -func (s *nodeSyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *nodeSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { pNode := pObj.(*corev1.Node) shouldSync, err := s.shouldSync(ctx.Context, pNode) if err != nil { diff --git a/pkg/controllers/resources/nodes/syncer_test.go b/pkg/controllers/resources/nodes/syncer_test.go index 4d809f6fd..86eb33a35 100644 --- a/pkg/controllers/resources/nodes/syncer_test.go +++ b/pkg/controllers/resources/nodes/syncer_test.go @@ -117,7 +117,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := newFakeSyncer(t, ctx) - _, err := syncer.SyncUp(syncCtx, baseNode) + _, err := syncer.SyncToVirtual(syncCtx, baseNode) assert.NilError(t, err) }, }, @@ -130,7 +130,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := newFakeSyncer(t, ctx) - _, err := syncer.SyncUp(syncCtx, baseNode) + _, err := syncer.SyncToVirtual(syncCtx, baseNode) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/persistentvolumeclaims/syncer.go b/pkg/controllers/resources/persistentvolumeclaims/syncer.go index e2a28f294..8a1354e5f 100644 --- a/pkg/controllers/resources/persistentvolumeclaims/syncer.go +++ b/pkg/controllers/resources/persistentvolumeclaims/syncer.go @@ -62,7 +62,7 @@ func (s *persistentVolumeClaimSyncer) WithOptions() *syncer.Options { var _ syncer.Syncer = &persistentVolumeClaimSyncer{} -func (s *persistentVolumeClaimSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *persistentVolumeClaimSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { vPvc := vObj.(*corev1.PersistentVolumeClaim) if vPvc.DeletionTimestamp != nil { // delete pvc immediately diff --git a/pkg/controllers/resources/persistentvolumeclaims/syncer_test.go b/pkg/controllers/resources/persistentvolumeclaims/syncer_test.go index 31c45fbd5..3d8e3d5f8 100644 --- a/pkg/controllers/resources/persistentvolumeclaims/syncer_test.go +++ b/pkg/controllers/resources/persistentvolumeclaims/syncer_test.go @@ -146,7 +146,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*persistentVolumeClaimSyncer).SyncDown(syncCtx, basePvc) + _, err := syncer.(*persistentVolumeClaimSyncer).SyncToHost(syncCtx, basePvc) assert.NilError(t, err) }, }, @@ -162,7 +162,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*persistentVolumeClaimSyncer).SyncDown(syncCtx, deletePvc) + _, err := syncer.(*persistentVolumeClaimSyncer).SyncToHost(syncCtx, deletePvc) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/persistentvolumes/fake_syncer.go b/pkg/controllers/resources/persistentvolumes/fake_syncer.go index 9d269ddc5..6b12d7e09 100644 --- a/pkg/controllers/resources/persistentvolumes/fake_syncer.go +++ b/pkg/controllers/resources/persistentvolumes/fake_syncer.go @@ -63,7 +63,7 @@ func (r *fakePersistentVolumeSyncer) ModifyController(_ *synccontext.RegisterCon var _ syncer.FakeSyncer = &fakePersistentVolumeSyncer{} -func (r *fakePersistentVolumeSyncer) FakeSyncUp(ctx *synccontext.SyncContext, req types.NamespacedName) (ctrl.Result, error) { +func (r *fakePersistentVolumeSyncer) FakeSyncToVirtual(ctx *synccontext.SyncContext, req types.NamespacedName) (ctrl.Result, error) { needed, err := r.pvNeeded(ctx, req.Name) if err != nil { return ctrl.Result{}, err diff --git a/pkg/controllers/resources/persistentvolumes/fake_syncer_test.go b/pkg/controllers/resources/persistentvolumes/fake_syncer_test.go index a68f8b349..dc5d3ef03 100644 --- a/pkg/controllers/resources/persistentvolumes/fake_syncer_test.go +++ b/pkg/controllers/resources/persistentvolumes/fake_syncer_test.go @@ -93,7 +93,7 @@ func TestFakeSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncContext, syncer := newFakeFakeSyncer(t, ctx) - _, err := syncer.FakeSyncUp(syncContext, basePvName) + _, err := syncer.FakeSyncToVirtual(syncContext, basePvName) assert.NilError(t, err) }, }, @@ -106,7 +106,7 @@ func TestFakeSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncContext, syncer := newFakeFakeSyncer(t, ctx) - _, err := syncer.FakeSyncUp(syncContext, basePvName) + _, err := syncer.FakeSyncToVirtual(syncContext, basePvName) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/persistentvolumes/syncer.go b/pkg/controllers/resources/persistentvolumes/syncer.go index 0c80062a7..db2c2d77e 100644 --- a/pkg/controllers/resources/persistentvolumes/syncer.go +++ b/pkg/controllers/resources/persistentvolumes/syncer.go @@ -85,7 +85,7 @@ func (s *persistentVolumeSyncer) ModifyController(_ *synccontext.RegisterContext var _ syncertypes.Syncer = &persistentVolumeSyncer{} -func (s *persistentVolumeSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *persistentVolumeSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { vPv := vObj.(*corev1.PersistentVolume) if vPv.DeletionTimestamp != nil || (vPv.Annotations != nil && vPv.Annotations[HostClusterPersistentVolumeAnnotation] != "") { if len(vPv.Finalizers) > 0 { @@ -217,9 +217,9 @@ func (s *persistentVolumeSyncer) WithOptions() *syncertypes.Options { return &syncertypes.Options{DisableUIDDeletion: true} } -var _ syncertypes.UpSyncer = &persistentVolumeSyncer{} +var _ syncertypes.ToVirtualSyncer = &persistentVolumeSyncer{} -func (s *persistentVolumeSyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *persistentVolumeSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { pPersistentVolume := pObj.(*corev1.PersistentVolume) sync, vPvc, err := s.shouldSync(ctx.Context, pPersistentVolume) if err != nil { @@ -283,11 +283,11 @@ func (s *persistentVolumeSyncer) IsManaged(ctx context.Context, pObj client.Obje return sync, nil } -func (s *persistentVolumeSyncer) VirtualToPhysical(_ context.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { +func (s *persistentVolumeSyncer) VirtualToHost(_ context.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { return types.NamespacedName{Name: translatePersistentVolumeName(req.Name, vObj)} } -func (s *persistentVolumeSyncer) PhysicalToVirtual(ctx context.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName { +func (s *persistentVolumeSyncer) HostToVirtual(ctx context.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName { if pObj != nil { pAnnotations := pObj.GetAnnotations() if pAnnotations != nil && pAnnotations[translate.NameAnnotation] != "" { diff --git a/pkg/controllers/resources/persistentvolumes/syncer_test.go b/pkg/controllers/resources/persistentvolumes/syncer_test.go index 88acffdf5..5cb9e8d51 100644 --- a/pkg/controllers/resources/persistentvolumes/syncer_test.go +++ b/pkg/controllers/resources/persistentvolumes/syncer_test.go @@ -209,7 +209,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncContext, syncer := newFakeSyncer(t, ctx) - _, err := syncer.SyncUp(syncContext, basePPv) + _, err := syncer.SyncToVirtual(syncContext, basePPv) assert.NilError(t, err) }, }, @@ -226,7 +226,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncContext, syncer := newFakeSyncer(t, ctx) - _, err := syncer.SyncUp(syncContext, wrongNsPPv) + _, err := syncer.SyncToVirtual(syncContext, wrongNsPPv) assert.NilError(t, err) }, }, @@ -243,7 +243,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncContext, syncer := newFakeSyncer(t, ctx) - _, err := syncer.SyncUp(syncContext, noPvcPPv) + _, err := syncer.SyncToVirtual(syncContext, noPvcPPv) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/poddisruptionbudgets/syncer.go b/pkg/controllers/resources/poddisruptionbudgets/syncer.go index 552ad5434..664a00257 100644 --- a/pkg/controllers/resources/poddisruptionbudgets/syncer.go +++ b/pkg/controllers/resources/poddisruptionbudgets/syncer.go @@ -19,7 +19,7 @@ type pdbSyncer struct { translator.NamespacedTranslator } -func (pdb *pdbSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (pdb *pdbSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { return pdb.SyncDownCreate(ctx, vObj, pdb.translate(ctx.Context, vObj.(*policyv1.PodDisruptionBudget))) } diff --git a/pkg/controllers/resources/poddisruptionbudgets/syncer_test.go b/pkg/controllers/resources/poddisruptionbudgets/syncer_test.go index 7a9a94498..212230313 100644 --- a/pkg/controllers/resources/poddisruptionbudgets/syncer_test.go +++ b/pkg/controllers/resources/poddisruptionbudgets/syncer_test.go @@ -92,7 +92,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*pdbSyncer).SyncDown(syncCtx, vclusterPDB) + _, err := syncer.(*pdbSyncer).SyncToHost(syncCtx, vclusterPDB) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/pods/syncer.go b/pkg/controllers/resources/pods/syncer.go index 5232248ff..990c7b3b3 100644 --- a/pkg/controllers/resources/pods/syncer.go +++ b/pkg/controllers/resources/pods/syncer.go @@ -151,7 +151,7 @@ func (s *podSyncer) ModifyController(ctx *synccontext.RegisterContext, builder * var _ syncer.Syncer = &podSyncer{} -func (s *podSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *podSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { vPod := vObj.(*corev1.Pod) // in some scenarios it is possible that the pod was already started and the physical pod // was deleted without vcluster's knowledge. In this case we are deleting the virtual pod diff --git a/pkg/controllers/resources/pods/syncer_test.go b/pkg/controllers/resources/pods/syncer_test.go index 4b52afd63..e7f22a673 100644 --- a/pkg/controllers/resources/pods/syncer_test.go +++ b/pkg/controllers/resources/pods/syncer_test.go @@ -454,7 +454,7 @@ func TestSync(t *testing.T) { ctx.Options.EnforceNodeSelector = true ctx.Options.NodeSelector = nodeSelectorOption syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*podSyncer).SyncDown(syncCtx, vPodWithNodeSelector.DeepCopy()) + _, err := syncer.(*podSyncer).SyncToHost(syncCtx, vPodWithNodeSelector.DeepCopy()) assert.NilError(t, err) }, }, @@ -470,7 +470,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*podSyncer).SyncDown(syncCtx, vPodPSS.DeepCopy()) + _, err := syncer.(*podSyncer).SyncToHost(syncCtx, vPodPSS.DeepCopy()) assert.NilError(t, err) }, }, @@ -487,7 +487,7 @@ func TestSync(t *testing.T) { Sync: func(ctx *synccontext.RegisterContext) { ctx.Options.EnforcePodSecurityStandard = string(api.LevelPrivileged) syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*podSyncer).SyncDown(syncCtx, vPodPSS.DeepCopy()) + _, err := syncer.(*podSyncer).SyncToHost(syncCtx, vPodPSS.DeepCopy()) assert.NilError(t, err) }, }, @@ -504,7 +504,7 @@ func TestSync(t *testing.T) { Sync: func(ctx *synccontext.RegisterContext) { ctx.Options.EnforcePodSecurityStandard = string(api.LevelRestricted) syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*podSyncer).SyncDown(syncCtx, vPodPSSR.DeepCopy()) + _, err := syncer.(*podSyncer).SyncToHost(syncCtx, vPodPSSR.DeepCopy()) assert.NilError(t, err) }, }, @@ -521,7 +521,7 @@ func TestSync(t *testing.T) { Sync: func(ctx *synccontext.RegisterContext) { ctx.Options.MountPhysicalHostPaths = true synccontext, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*podSyncer).SyncDown(synccontext, vHostPathPod.DeepCopy()) + _, err := syncer.(*podSyncer).SyncToHost(synccontext, vHostPathPod.DeepCopy()) assert.NilError(t, err) }, }, @@ -553,7 +553,7 @@ func TestSync(t *testing.T) { Sync: func(ctx *synccontext.RegisterContext) { ctx.Options.SyncLabels = []string{syncLabelsWildcard} syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*podSyncer).SyncDown(syncCtx, vPodWithLabels.DeepCopy()) + _, err := syncer.(*podSyncer).SyncToHost(syncCtx, vPodWithLabels.DeepCopy()) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/priorityclasses/syncer.go b/pkg/controllers/resources/priorityclasses/syncer.go index fc9404c43..bcb73ecaf 100644 --- a/pkg/controllers/resources/priorityclasses/syncer.go +++ b/pkg/controllers/resources/priorityclasses/syncer.go @@ -31,7 +31,7 @@ func (s *priorityClassSyncer) RegisterIndices(ctx *synccontext.RegisterContext) var _ syncer.Syncer = &priorityClassSyncer{} -func (s *priorityClassSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *priorityClassSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { newPriorityClass := s.translate(ctx.Context, vObj.(*schedulingv1.PriorityClass)) ctx.Log.Infof("create physical priority class %s", newPriorityClass.Name) err := ctx.PhysicalClient.Create(ctx.Context, newPriorityClass) diff --git a/pkg/controllers/resources/secrets/syncer.go b/pkg/controllers/resources/secrets/syncer.go index 54aaf9daa..44995a190 100644 --- a/pkg/controllers/resources/secrets/syncer.go +++ b/pkg/controllers/resources/secrets/syncer.go @@ -100,7 +100,7 @@ func (s *secretSyncer) ModifyController(_ *synccontext.RegisterContext, builder return builder.Watches(&corev1.Pod{}, handler.EnqueueRequestsFromMapFunc(mapPods)), nil } -func (s *secretSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *secretSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { createNeeded, err := s.isSecretUsed(ctx, vObj) if err != nil { return ctrl.Result{}, err diff --git a/pkg/controllers/resources/secrets/syncer_test.go b/pkg/controllers/resources/secrets/syncer_test.go index afde901d0..26726475d 100644 --- a/pkg/controllers/resources/secrets/syncer_test.go +++ b/pkg/controllers/resources/secrets/syncer_test.go @@ -91,7 +91,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncContext, syncer := newFakeSyncer(t, ctx) - _, err := syncer.(*secretSyncer).SyncDown(syncContext, baseSecret) + _, err := syncer.(*secretSyncer).SyncToHost(syncContext, baseSecret) assert.NilError(t, err) }, }, @@ -109,7 +109,7 @@ func TestSync(t *testing.T) { Sync: func(ctx *synccontext.RegisterContext) { ctx.Options.SyncLabels = []string{testLabel} syncContext, syncer := newFakeSyncer(t, ctx) - _, err := syncer.(*secretSyncer).SyncDown(syncContext, baseSecret) + _, err := syncer.(*secretSyncer).SyncToHost(syncContext, baseSecret) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/serviceaccounts/syncer.go b/pkg/controllers/resources/serviceaccounts/syncer.go index 5f3dcbc0a..5fc91d69f 100644 --- a/pkg/controllers/resources/serviceaccounts/syncer.go +++ b/pkg/controllers/resources/serviceaccounts/syncer.go @@ -20,7 +20,7 @@ type serviceAccountSyncer struct { translator.NamespacedTranslator } -func (s *serviceAccountSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *serviceAccountSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { return s.SyncDownCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*corev1.ServiceAccount))) } diff --git a/pkg/controllers/resources/serviceaccounts/syncer_test.go b/pkg/controllers/resources/serviceaccounts/syncer_test.go index da563ed91..5e52701b9 100644 --- a/pkg/controllers/resources/serviceaccounts/syncer_test.go +++ b/pkg/controllers/resources/serviceaccounts/syncer_test.go @@ -62,7 +62,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*serviceAccountSyncer).SyncDown(syncCtx, vSA) + _, err := syncer.(*serviceAccountSyncer).SyncToHost(syncCtx, vSA) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/services/syncer.go b/pkg/controllers/resources/services/syncer.go index 986f24c2c..4ad072f52 100644 --- a/pkg/controllers/resources/services/syncer.go +++ b/pkg/controllers/resources/services/syncer.go @@ -44,7 +44,7 @@ func (s *serviceSyncer) WithOptions() *syncertypes.Options { return &syncertypes.Options{DisableUIDDeletion: true} } -func (s *serviceSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *serviceSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { return s.SyncDownCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*corev1.Service))) } @@ -110,9 +110,9 @@ func isSwitchingFromExternalName(pService *corev1.Service, vService *corev1.Serv return vService.Spec.Type == corev1.ServiceTypeExternalName && pService.Spec.Type != vService.Spec.Type && pService.Spec.ClusterIP != "" } -var _ syncertypes.UpSyncer = &serviceSyncer{} +var _ syncertypes.ToVirtualSyncer = &serviceSyncer{} -func (s *serviceSyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *serviceSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { if !translate.Default.IsManaged(pObj) { return ctrl.Result{}, nil } diff --git a/pkg/controllers/resources/services/syncer_test.go b/pkg/controllers/resources/services/syncer_test.go index 3459a08b1..83593e686 100644 --- a/pkg/controllers/resources/services/syncer_test.go +++ b/pkg/controllers/resources/services/syncer_test.go @@ -314,7 +314,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*serviceSyncer).SyncDown(syncCtx, baseService) + _, err := syncer.(*serviceSyncer).SyncToHost(syncCtx, baseService) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/storageclasses/host_sc_syncer.go b/pkg/controllers/resources/storageclasses/host_sc_syncer.go index 4e36edaac..1970488b4 100644 --- a/pkg/controllers/resources/storageclasses/host_sc_syncer.go +++ b/pkg/controllers/resources/storageclasses/host_sc_syncer.go @@ -19,9 +19,9 @@ type hostStorageClassSyncer struct { translator.Translator } -var _ syncer.UpSyncer = &hostStorageClassSyncer{} +var _ syncer.ToVirtualSyncer = &hostStorageClassSyncer{} -func (s *hostStorageClassSyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *hostStorageClassSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { vObj := s.translateBackwards(ctx.Context, pObj.(*storagev1.StorageClass)) ctx.Log.Infof("create storage class %s, because it does not exist in virtual cluster", vObj.Name) return ctrl.Result{}, ctx.VirtualClient.Create(ctx.Context, vObj) @@ -41,7 +41,7 @@ func (s *hostStorageClassSyncer) Sync(ctx *synccontext.SyncContext, pObj client. return ctrl.Result{}, nil } -func (s *hostStorageClassSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *hostStorageClassSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { ctx.Log.Infof("delete virtual storage class %s, because physical object is missing", vObj.GetName()) return ctrl.Result{}, ctx.VirtualClient.Delete(ctx.Context, vObj) } diff --git a/pkg/controllers/resources/storageclasses/syncer.go b/pkg/controllers/resources/storageclasses/syncer.go index 04b5b4691..e06e9f3df 100644 --- a/pkg/controllers/resources/storageclasses/syncer.go +++ b/pkg/controllers/resources/storageclasses/syncer.go @@ -50,7 +50,7 @@ func (s *storageClassSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Obje return ctrl.Result{}, nil } -func (s *storageClassSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *storageClassSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { newStorageClass := s.translate(ctx.Context, vObj.(*storagev1.StorageClass)) ctx.Log.Infof("create physical storage class %s", newStorageClass.Name) err := ctx.PhysicalClient.Create(ctx.Context, newStorageClass) diff --git a/pkg/controllers/resources/storageclasses/syncer_test.go b/pkg/controllers/resources/storageclasses/syncer_test.go index 94343c9be..565a04d15 100644 --- a/pkg/controllers/resources/storageclasses/syncer_test.go +++ b/pkg/controllers/resources/storageclasses/syncer_test.go @@ -73,7 +73,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*storageClassSyncer).SyncDown(syncCtx, vObject) + _, err := syncer.(*storageClassSyncer).SyncToHost(syncCtx, vObject) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/volumesnapshots/volumesnapshotclasses/syncer.go b/pkg/controllers/resources/volumesnapshots/volumesnapshotclasses/syncer.go index 418629078..69f04baf9 100644 --- a/pkg/controllers/resources/volumesnapshots/volumesnapshotclasses/syncer.go +++ b/pkg/controllers/resources/volumesnapshots/volumesnapshotclasses/syncer.go @@ -27,9 +27,9 @@ func (s *volumeSnapshotClassSyncer) Init(registerContext *synccontext.RegisterCo return util.EnsureCRD(registerContext.Context, registerContext.VirtualManager.GetConfig(), []byte(volumeSnapshotClassesCRD), volumesnapshotv1.SchemeGroupVersion.WithKind("VolumeSnapshotClass")) } -var _ syncer.UpSyncer = &volumeSnapshotClassSyncer{} +var _ syncer.ToVirtualSyncer = &volumeSnapshotClassSyncer{} -func (s *volumeSnapshotClassSyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *volumeSnapshotClassSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { pVolumeSnapshotClass := pObj.(*volumesnapshotv1.VolumeSnapshotClass) vObj := s.translateBackwards(ctx.Context, pVolumeSnapshotClass) ctx.Log.Infof("create VolumeSnapshotClass %s, because it does not exist in the virtual cluster", vObj.Name) @@ -38,7 +38,7 @@ func (s *volumeSnapshotClassSyncer) SyncUp(ctx *synccontext.SyncContext, pObj cl var _ syncer.Syncer = &volumeSnapshotClassSyncer{} -func (s *volumeSnapshotClassSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *volumeSnapshotClassSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { // We are not doing any syncing Forward for the VolumeSnapshotClasses // if this method is called it means that VolumeSnapshotClass was deleted in host or // a new VolumeSnapshotClass was created in vcluster, and it should be deleted to avoid confusion diff --git a/pkg/controllers/resources/volumesnapshots/volumesnapshotclasses/syncer_test.go b/pkg/controllers/resources/volumesnapshots/volumesnapshotclasses/syncer_test.go index 87f647581..4366d35ff 100644 --- a/pkg/controllers/resources/volumesnapshots/volumesnapshotclasses/syncer_test.go +++ b/pkg/controllers/resources/volumesnapshots/volumesnapshotclasses/syncer_test.go @@ -44,7 +44,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*volumeSnapshotClassSyncer).SyncUp(syncCtx, vBaseVSC.DeepCopy()) + _, err := syncer.(*volumeSnapshotClassSyncer).SyncToVirtual(syncCtx, vBaseVSC.DeepCopy()) assert.NilError(t, err) }, }, @@ -88,7 +88,7 @@ func TestSync(t *testing.T) { ExpectedPhysicalState: map[schema.GroupVersionKind][]runtime.Object{}, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*volumeSnapshotClassSyncer).SyncDown(syncCtx, vBaseVSC.DeepCopy()) + _, err := syncer.(*volumeSnapshotClassSyncer).SyncToHost(syncCtx, vBaseVSC.DeepCopy()) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/volumesnapshots/volumesnapshotcontents/syncer.go b/pkg/controllers/resources/volumesnapshots/volumesnapshotcontents/syncer.go index 732d9f8f6..cccacbad8 100644 --- a/pkg/controllers/resources/volumesnapshots/volumesnapshotcontents/syncer.go +++ b/pkg/controllers/resources/volumesnapshots/volumesnapshotcontents/syncer.go @@ -65,9 +65,9 @@ func newIndexByVSCPhysicalName() client.IndexerFunc { } } -var _ syncer.UpSyncer = &volumeSnapshotContentSyncer{} +var _ syncer.ToVirtualSyncer = &volumeSnapshotContentSyncer{} -func (s *volumeSnapshotContentSyncer) SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { +func (s *volumeSnapshotContentSyncer) SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) { pVSC := pObj.(*volumesnapshotv1.VolumeSnapshotContent) // check if the VolumeSnapshotContent should get synced sync, vVS, err := s.shouldSync(ctx.Context, pVSC) @@ -85,7 +85,7 @@ func (s *volumeSnapshotContentSyncer) SyncUp(ctx *synccontext.SyncContext, pObj var _ syncer.Syncer = &volumeSnapshotContentSyncer{} -func (s *volumeSnapshotContentSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *volumeSnapshotContentSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { vVSC := vObj.(*volumesnapshotv1.VolumeSnapshotContent) if vVSC.DeletionTimestamp != nil || (vVSC.Annotations != nil && vVSC.Annotations[HostClusterVSCAnnotation] != "") { if len(vVSC.Finalizers) > 0 { @@ -241,11 +241,11 @@ func (s *volumeSnapshotContentSyncer) IsManaged(ctx context.Context, pObj client return sync, nil } -func (s *volumeSnapshotContentSyncer) VirtualToPhysical(_ context.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { +func (s *volumeSnapshotContentSyncer) VirtualToHost(_ context.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { return types.NamespacedName{Name: translateVolumeSnapshotContentName(req.Name, vObj)} } -func (s *volumeSnapshotContentSyncer) PhysicalToVirtual(ctx context.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName { +func (s *volumeSnapshotContentSyncer) HostToVirtual(ctx context.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName { if pObj != nil { pAnnotations := pObj.GetAnnotations() if pAnnotations != nil && pAnnotations[translate.NameAnnotation] != "" { diff --git a/pkg/controllers/resources/volumesnapshots/volumesnapshotcontents/syncer_test.go b/pkg/controllers/resources/volumesnapshots/volumesnapshotcontents/syncer_test.go index 6be556f4d..9dbd24c82 100644 --- a/pkg/controllers/resources/volumesnapshots/volumesnapshotcontents/syncer_test.go +++ b/pkg/controllers/resources/volumesnapshots/volumesnapshotcontents/syncer_test.go @@ -178,7 +178,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := newFakeSyncer(t, ctx) - _, err := syncer.SyncUp(syncCtx, pDynamic.DeepCopy()) + _, err := syncer.SyncToVirtual(syncCtx, pDynamic.DeepCopy()) assert.NilError(t, err) }, }, @@ -194,7 +194,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := newFakeSyncer(t, ctx) - _, err := syncer.SyncDown(syncCtx, vPreProvisioned.DeepCopy()) + _, err := syncer.SyncToHost(syncCtx, vPreProvisioned.DeepCopy()) assert.NilError(t, err) }, }, @@ -288,7 +288,7 @@ func TestSync(t *testing.T) { volumesnapshotv1.SchemeGroupVersion.WithKind("VolumeSnapshotContent"): {}}, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := newFakeSyncer(t, ctx) - _, err := syncer.SyncDown(syncCtx, vDeletingWithGCFinalizer.DeepCopy()) + _, err := syncer.SyncToHost(syncCtx, vDeletingWithGCFinalizer.DeepCopy()) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer.go b/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer.go index 8499c9c7e..b060592ae 100644 --- a/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer.go +++ b/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer.go @@ -43,7 +43,7 @@ func (s *volumeSnapshotSyncer) Init(registerContext *synccontext.RegisterContext var _ syncer.Syncer = &volumeSnapshotSyncer{} -func (s *volumeSnapshotSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *volumeSnapshotSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { vVS := vObj.(*volumesnapshotv1.VolumeSnapshot) if vVS.DeletionTimestamp != nil { // delete volume snapshot immediately diff --git a/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer_test.go b/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer_test.go index 14a4f02a5..1c1006049 100644 --- a/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer_test.go +++ b/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer_test.go @@ -113,7 +113,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*volumeSnapshotSyncer).SyncDown(syncCtx, vPVSourceSnapshot.DeepCopy()) + _, err := syncer.(*volumeSnapshotSyncer).SyncToHost(syncCtx, vPVSourceSnapshot.DeepCopy()) assert.NilError(t, err) }, }, @@ -129,7 +129,7 @@ func TestSync(t *testing.T) { }, Sync: func(ctx *synccontext.RegisterContext) { syncCtx, syncer := generictesting.FakeStartSyncer(t, ctx, New) - _, err := syncer.(*volumeSnapshotSyncer).SyncDown(syncCtx, vVSCSourceSnapshot.DeepCopy()) + _, err := syncer.(*volumeSnapshotSyncer).SyncToHost(syncCtx, vVSCSourceSnapshot.DeepCopy()) assert.NilError(t, err) }, }, diff --git a/pkg/controllers/syncer/fake_syncer.go b/pkg/controllers/syncer/fake_syncer.go index 2ebfafa23..6c10eb015 100644 --- a/pkg/controllers/syncer/fake_syncer.go +++ b/pkg/controllers/syncer/fake_syncer.go @@ -71,7 +71,7 @@ func (r *fakeSyncer) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } - return r.syncer.FakeSyncUp(syncContext, req.NamespacedName) + return r.syncer.FakeSyncToVirtual(syncContext, req.NamespacedName) } // check if we should skip resource diff --git a/pkg/controllers/syncer/syncer.go b/pkg/controllers/syncer/syncer.go index 57ca4a418..fdb462e08 100644 --- a/pkg/controllers/syncer/syncer.go +++ b/pkg/controllers/syncer/syncer.go @@ -117,7 +117,7 @@ func (r *syncerController) Reconcile(ctx context.Context, origReq ctrl.Request) // check what function we should call if vObj != nil && pObj == nil { - return r.syncer.SyncDown(syncContext, vObj) + return r.syncer.SyncToHost(syncContext, vObj) } else if vObj != nil && pObj != nil { // make sure the object uid matches pAnnotations := pObj.GetAnnotations() @@ -140,10 +140,10 @@ func (r *syncerController) Reconcile(ctx context.Context, origReq ctrl.Request) } } - // check if up syncer - upSyncer, ok := r.syncer.(syncertypes.UpSyncer) + // check if virtual syncer + toVirtual, ok := r.syncer.(syncertypes.ToVirtualSyncer) if ok { - return upSyncer.SyncUp(syncContext, pObj) + return toVirtual.SyncToVirtual(syncContext, pObj) } return DeleteObject(syncContext, pObj, "virtual object was deleted") @@ -172,7 +172,7 @@ func (r *syncerController) getObjectsFromPhysical(ctx *synccontext.SyncContext, } // get virtual object - exclude, vObj, err = r.getVirtualObject(ctx.Context, r.syncer.PhysicalToVirtual(ctx.Context, req.NamespacedName, pObj)) + exclude, vObj, err = r.getVirtualObject(ctx.Context, r.syncer.HostToVirtual(ctx.Context, req.NamespacedName, pObj)) if err != nil { return nil, nil, err } else if exclude { @@ -192,7 +192,7 @@ func (r *syncerController) getObjectsFromVirtual(ctx *synccontext.SyncContext, r } // get physical object - exclude, pObj, err = r.getPhysicalObject(ctx.Context, r.syncer.VirtualToPhysical(ctx.Context, req.NamespacedName, vObj), vObj) + exclude, pObj, err = r.getPhysicalObject(ctx.Context, r.syncer.VirtualToHost(ctx.Context, req.NamespacedName, vObj), vObj) if err != nil { return nil, nil, err } else if exclude { @@ -319,7 +319,7 @@ func (r *syncerController) extractRequest(ctx context.Context, req ctrl.Request) } // try to get virtual name from physical - req.NamespacedName = r.syncer.PhysicalToVirtual(ctx, pReq.NamespacedName, pObj) + req.NamespacedName = r.syncer.HostToVirtual(ctx, pReq.NamespacedName, pObj) } return req, pReq, nil @@ -332,7 +332,7 @@ func (r *syncerController) enqueueVirtual(ctx context.Context, obj client.Object // add a new request for the host object as otherwise this information might be lost after a delete event if isDelete { - name := r.syncer.VirtualToPhysical(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, obj) + name := r.syncer.VirtualToHost(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, obj) if name.Name != "" { q.Add(toHostRequest(reconcile.Request{ NamespacedName: name, @@ -365,7 +365,7 @@ func (r *syncerController) enqueuePhysical(ctx context.Context, obj client.Objec // add a new request for the virtual object as otherwise this information might be lost after a delete event if isDelete { - name := r.syncer.PhysicalToVirtual(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, obj) + name := r.syncer.HostToVirtual(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, obj) if name.Name != "" { q.Add(reconcile.Request{ NamespacedName: name, diff --git a/pkg/controllers/syncer/syncer_test.go b/pkg/controllers/syncer/syncer_test.go index 599d5d79f..a5eb51940 100644 --- a/pkg/controllers/syncer/syncer_test.go +++ b/pkg/controllers/syncer/syncer_test.go @@ -48,7 +48,7 @@ func (s *mockSyncer) naiveTranslateUpdate(ctx *synccontext.SyncContext, vObj cli } // SyncDown is called when a virtual object was created and needs to be synced down to the physical cluster -func (s *mockSyncer) SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { +func (s *mockSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { return s.SyncDownCreate(ctx, vObj, s.naiveTranslateCreate(ctx, vObj)) } diff --git a/pkg/controllers/syncer/translator/cluster_translator.go b/pkg/controllers/syncer/translator/cluster_translator.go index 6733ab2e6..191e3049c 100644 --- a/pkg/controllers/syncer/translator/cluster_translator.go +++ b/pkg/controllers/syncer/translator/cluster_translator.go @@ -44,13 +44,13 @@ func (n *clusterTranslator) IsManaged(_ context2.Context, pObj client.Object) (b return translate.Default.IsManagedCluster(pObj), nil } -func (n *clusterTranslator) VirtualToPhysical(_ context2.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { +func (n *clusterTranslator) VirtualToHost(_ context2.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { return types.NamespacedName{ Name: n.nameTranslator(req.Name, vObj), } } -func (n *clusterTranslator) PhysicalToVirtual(ctx context2.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName { +func (n *clusterTranslator) HostToVirtual(ctx context2.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName { if pObj != nil { pAnnotations := pObj.GetAnnotations() if pAnnotations != nil && pAnnotations[translate.NameAnnotation] != "" { diff --git a/pkg/controllers/syncer/translator/mirror_name_translator.go b/pkg/controllers/syncer/translator/mirror_name_translator.go index 087c79f40..207445cf9 100644 --- a/pkg/controllers/syncer/translator/mirror_name_translator.go +++ b/pkg/controllers/syncer/translator/mirror_name_translator.go @@ -47,10 +47,10 @@ func (n *mirrorPhysicalTranslator) IsManaged(context.Context, client.Object) (bo return true, nil } -func (n *mirrorPhysicalTranslator) VirtualToPhysical(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { +func (n *mirrorPhysicalTranslator) VirtualToHost(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { return req } -func (n *mirrorPhysicalTranslator) PhysicalToVirtual(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { +func (n *mirrorPhysicalTranslator) HostToVirtual(_ context.Context, req types.NamespacedName, _ client.Object) types.NamespacedName { return req } diff --git a/pkg/controllers/syncer/translator/namespaced_translator.go b/pkg/controllers/syncer/translator/namespaced_translator.go index 24a1c4beb..3ec07df4c 100644 --- a/pkg/controllers/syncer/translator/namespaced_translator.go +++ b/pkg/controllers/syncer/translator/namespaced_translator.go @@ -103,7 +103,7 @@ func (n *namespacedTranslator) IsManaged(_ context2.Context, pObj client.Object) return translate.Default.IsManaged(pObj), nil } -func (n *namespacedTranslator) VirtualToPhysical(_ context2.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { +func (n *namespacedTranslator) VirtualToHost(_ context2.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName { name := translate.Default.PhysicalName(req.Name, req.Namespace) if n.nameTranslator != nil { name = n.nameTranslator(req, vObj) @@ -115,7 +115,7 @@ func (n *namespacedTranslator) VirtualToPhysical(_ context2.Context, req types.N } } -func (n *namespacedTranslator) PhysicalToVirtual(_ context2.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName { +func (n *namespacedTranslator) HostToVirtual(_ context2.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName { if pObj != nil { pAnnotations := pObj.GetAnnotations() if pAnnotations != nil && pAnnotations[translate.NameAnnotation] != "" { @@ -147,7 +147,7 @@ func (n *namespacedTranslator) TranslateMetadata(ctx context2.Context, vObj clie // reset metadata & translate name and namespace translate.ResetObjectMetadata(m) - m.SetName(n.VirtualToPhysical(ctx, types.NamespacedName{Name: vObj.GetName(), Namespace: vObj.GetNamespace()}, vObj).Name) + m.SetName(n.VirtualToHost(ctx, types.NamespacedName{Name: vObj.GetName(), Namespace: vObj.GetNamespace()}, vObj).Name) if vObj.GetNamespace() != "" { m.SetNamespace(translate.Default.PhysicalNamespace(vObj.GetNamespace())) diff --git a/pkg/controllers/syncer/translator/translator.go b/pkg/controllers/syncer/translator/translator.go index aa3d796eb..1a73a9506 100644 --- a/pkg/controllers/syncer/translator/translator.go +++ b/pkg/controllers/syncer/translator/translator.go @@ -24,11 +24,11 @@ type NameTranslator interface { // IsManaged determines if a physical object is managed by the vcluster IsManaged(context.Context, client.Object) (bool, error) - // VirtualToPhysical translates a virtual name to a physical name - VirtualToPhysical(ctx context.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName + // VirtualToHost translates a virtual name to a physical name + VirtualToHost(ctx context.Context, req types.NamespacedName, vObj client.Object) types.NamespacedName - // PhysicalToVirtual translates a physical name to a virtual name - PhysicalToVirtual(ctx context.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName + // HostToVirtual translates a physical name to a virtual name + HostToVirtual(ctx context.Context, req types.NamespacedName, pObj client.Object) types.NamespacedName } // MetadataTranslator is used to convert metadata between virtual and physical objects and vice versa @@ -57,6 +57,6 @@ type NamespacedTranslator interface { // SyncDownUpdate updates the given pObj (if not nil) in the target namespace SyncDownUpdate(ctx *syncercontext.SyncContext, vObj, pObj client.Object) (ctrl.Result, error) - // Function to override default VirtualToPhysical name translation + // Function to override default VirtualToHost name translation SetNameTranslator(nameTranslator translate.PhysicalNamespacedNameTranslator) } diff --git a/pkg/types/types.go b/pkg/types/types.go index 09dfe4a1f..c38a5e5b2 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -27,21 +27,21 @@ type Syncer interface { Object translator.NameTranslator - // SyncDown is called when a virtual object was created and needs to be synced down to the physical cluster - SyncDown(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) + // SyncToHost is called when a virtual object was created and needs to be synced down to the physical cluster + SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) // Sync is called to sync a virtual object with a physical object Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) } -type UpSyncer interface { - // SyncUp is called when a physical object exists but the virtual object does not exist - SyncUp(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) +type ToVirtualSyncer interface { + // SyncToVirtual is called when a host object exists but the virtual object does not exist + SyncToVirtual(ctx *synccontext.SyncContext, pObj client.Object) (ctrl.Result, error) } type FakeSyncer interface { Object - FakeSyncUp(ctx *synccontext.SyncContext, req types.NamespacedName) (ctrl.Result, error) + FakeSyncToVirtual(ctx *synccontext.SyncContext, req types.NamespacedName) (ctrl.Result, error) FakeSync(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) }