diff --git a/docs/pages/advanced-topics/plugins-development.mdx b/docs/pages/advanced-topics/plugins-development.mdx index e2ac7fb6a..6e0b2f327 100644 --- a/docs/pages/advanced-topics/plugins-development.mdx +++ b/docs/pages/advanced-topics/plugins-development.mdx @@ -82,11 +82,11 @@ 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. +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 `SyncToHostCreate` 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) SyncToHost(ctx *syncercontext.syncercontext, vObj client.Object) (ctrl.Result, error) { - return s.SyncDownCreate(ctx, vObj, s.translate(vObj.(*corev1.ConfigMap))) + return s.SyncToHostCreate(ctx, vObj, s.translate(vObj.(*corev1.ConfigMap))) } func (s *configMapSyncer) translate(vObj client.Object) *corev1.ConfigMap { @@ -96,12 +96,12 @@ func (s *configMapSyncer) translate(vObj client.Object) *corev1.ConfigMap { The `TranslateMetadata` function used above produces a ConfigMap object that will be created in the host cluster. It is a deep copy of the ConfigMap from vCluster, but with certain metadata modifications - the name and labels are transformed, some vCluster labels and annotations are added, and many metadata fields are stripped (uid, resourceVersion, etc.). -Next, we need to implement code that will handle the updates of the ConfigMap. When a ConfigMap in vCluster or host cluster is updated, the vCluster SDK will call the `Sync` function of the syncer. Current ConfigMap resources from the host cluster and from vCluster are passed as the second and third parameters respectively. In the implementation below, you can see another pattern used by the vCluster syncers. The `translateUpdate` function will return nil when no change to the ConfigMap in the host cluster is needed, and the `SyncDownUpdate` function will not do an unnecessary update API call in such case. +Next, we need to implement code that will handle the updates of the ConfigMap. When a ConfigMap in vCluster or host cluster is updated, the vCluster SDK will call the `Sync` function of the syncer. Current ConfigMap resources from the host cluster and from vCluster are passed as the second and third parameters respectively. In the implementation below, you can see another pattern used by the vCluster syncers. The `translateUpdate` function will return nil when no change to the ConfigMap in the host cluster is needed, and the `SyncToHostUpdate` function will not do an unnecessary update API call in such case. ``` func (s *configMapSyncer) Sync(ctx *syncercontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { - return s.SyncDownUpdate(ctx, vObj, s.translateUpdate(pObj.(*corev1.ConfigMap), vObj.(*corev1.ConfigMap))) + return s.SyncToHostUpdate(ctx, vObj, s.translateUpdate(pObj.(*corev1.ConfigMap), vObj.(*corev1.ConfigMap))) } func (s *configMapSyncer) translateUpdate(pObj, vObj *corev1.ConfigMap) *corev1.ConfigMap { diff --git a/docs/pages/plugins/tutorial.mdx b/docs/pages/plugins/tutorial.mdx index 7a97b41f6..a108739a1 100644 --- a/docs/pages/plugins/tutorial.mdx +++ b/docs/pages/plugins/tutorial.mdx @@ -90,26 +90,26 @@ type carSyncer struct { After an import block, we see the `NewCarSyncer` function, which is being called from the `main.go`. It returns a new instance of the `carSyncer` struct, which is defined by a single nested anonymous struct of type `NamespacedTranslator`. The `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`. -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. +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 `SyncToHostCreate` 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) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { - return s.SyncDownCreate(ctx, vObj, s.TranslateMetadata(ctx.Context, vObj).(*examplev1.Car)) + return s.SyncToHostCreate(ctx, vObj, s.TranslateMetadata(ctx.Context, vObj).(*examplev1.Car)) } func (s *carSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { - return s.SyncDownUpdate(ctx, vObj, s.translateUpdate(ctx.Context, pObj.(*examplev1.Car), vObj.(*examplev1.Car))) + return s.SyncToHostUpdate(ctx, vObj, s.translateUpdate(ctx.Context, pObj.(*examplev1.Car), vObj.(*examplev1.Car))) } ``` The `TranslateMetadata` function used above produces a Car object that will be created in the host cluster. It is a deep copy of the Car from vCluster, but with certain metadata modifications - the name and labels are transformed, some vCluster labels and annotations are added, many metadata fields are stripped (uid, resourceVersion, etc.). -Next, we need to implement code that will handle the updates of the Car. When a CAr in vCluster or host cluster is updated, the vCluster SDK will call the `Sync` function of the syncer. Current Car resource from the host cluster and from vCluster are passed as the second and third parameters respectively. In the implementation below, you can see another pattern used by the vCluster syncers. The `translateUpdate` function will return nil when no change to the Car in the host cluster is needed, and the `SyncDownUpdate` function will not do an unnecessary update API call in such case. +Next, we need to implement code that will handle the updates of the Car. When a CAr in vCluster or host cluster is updated, the vCluster SDK will call the `Sync` function of the syncer. Current Car resource from the host cluster and from vCluster are passed as the second and third parameters respectively. In the implementation below, you can see another pattern used by the vCluster syncers. The `translateUpdate` function will return nil when no change to the Car in the host cluster is needed, and the `SyncToHostUpdate` function will not do an unnecessary update API call in such case. ``` func (s *carSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { - return s.SyncDownUpdate(ctx, vObj, s.translateUpdate(ctx.Context, pObj.(*examplev1.Car), vObj.(*examplev1.Car))) + return s.SyncToHostUpdate(ctx, vObj, s.translateUpdate(ctx.Context, pObj.(*examplev1.Car), vObj.(*examplev1.Car))) } func (s *carSyncer) translateUpdate(ctx context.Context, pObj, vObj *examplev1.Car) *examplev1.Car { diff --git a/pkg/controllers/resources/configmaps/syncer.go b/pkg/controllers/resources/configmaps/syncer.go index 14df795d8..ae71c0e29 100644 --- a/pkg/controllers/resources/configmaps/syncer.go +++ b/pkg/controllers/resources/configmaps/syncer.go @@ -74,7 +74,7 @@ func (s *configMapSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.O return ctrl.Result{}, nil } - return s.SyncDownCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*corev1.ConfigMap))) + return s.SyncToHostCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*corev1.ConfigMap))) } func (s *configMapSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -99,7 +99,7 @@ func (s *configMapSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, } // did the configmap change? - return s.SyncDownUpdate(ctx, vObj, newConfigMap) + return s.SyncToHostUpdate(ctx, vObj, newConfigMap) } func (s *configMapSyncer) isConfigMapUsed(ctx *synccontext.SyncContext, vObj runtime.Object) (bool, error) { diff --git a/pkg/controllers/resources/endpoints/syncer.go b/pkg/controllers/resources/endpoints/syncer.go index 9b6db75b3..0856d9095 100644 --- a/pkg/controllers/resources/endpoints/syncer.go +++ b/pkg/controllers/resources/endpoints/syncer.go @@ -25,7 +25,7 @@ type endpointsSyncer struct { } func (s *endpointsSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { - return s.SyncDownCreate(ctx, vObj, s.translate(ctx.Context, vObj)) + return s.SyncToHostCreate(ctx, vObj, s.translate(ctx.Context, vObj)) } func (s *endpointsSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -34,7 +34,7 @@ func (s *endpointsSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, translator.PrintChanges(pObj, newEndpoints, ctx.Log) } - return s.SyncDownUpdate(ctx, vObj, newEndpoints) + return s.SyncToHostUpdate(ctx, vObj, newEndpoints) } var _ syncer.Starter = &endpointsSyncer{} diff --git a/pkg/controllers/resources/ingresses/legacy/syncer.go b/pkg/controllers/resources/ingresses/legacy/syncer.go index 0c45eba6f..e3a04ba25 100644 --- a/pkg/controllers/resources/ingresses/legacy/syncer.go +++ b/pkg/controllers/resources/ingresses/legacy/syncer.go @@ -24,7 +24,7 @@ type ingressSyncer struct { var _ syncertypes.Syncer = &ingressSyncer{} 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))) + return s.SyncToHostCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*networkingv1beta1.Ingress))) } func (s *ingressSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -63,7 +63,7 @@ func (s *ingressSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, v translator.PrintChanges(pObj, newIngress, ctx.Log) } - return s.SyncDownUpdate(ctx, vObj, newIngress) + return s.SyncToHostUpdate(ctx, vObj, newIngress) } func SecretNamesFromIngress(ingress *networkingv1beta1.Ingress) []string { diff --git a/pkg/controllers/resources/ingresses/syncer.go b/pkg/controllers/resources/ingresses/syncer.go index 278ab2b95..6add86358 100644 --- a/pkg/controllers/resources/ingresses/syncer.go +++ b/pkg/controllers/resources/ingresses/syncer.go @@ -26,7 +26,7 @@ type ingressSyncer struct { var _ syncertypes.Syncer = &ingressSyncer{} 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))) + return s.SyncToHostCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*networkingv1.Ingress))) } func (s *ingressSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -65,7 +65,7 @@ func (s *ingressSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, v translator.PrintChanges(pObj, newIngress, ctx.Log) } - return s.SyncDownUpdate(ctx, vObj, newIngress) + return s.SyncToHostUpdate(ctx, vObj, newIngress) } func SecretNamesFromIngress(ingress *networkingv1.Ingress) []string { diff --git a/pkg/controllers/resources/networkpolicies/syncer.go b/pkg/controllers/resources/networkpolicies/syncer.go index 15858ae99..ed614d2d9 100644 --- a/pkg/controllers/resources/networkpolicies/syncer.go +++ b/pkg/controllers/resources/networkpolicies/syncer.go @@ -23,7 +23,7 @@ type networkPolicySyncer struct { var _ syncertypes.Syncer = &networkPolicySyncer{} 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))) + return s.SyncToHostCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*networkingv1.NetworkPolicy))) } func (s *networkPolicySyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -32,5 +32,5 @@ func (s *networkPolicySyncer) Sync(ctx *synccontext.SyncContext, pObj client.Obj translator.PrintChanges(pObj, newNetworkPolicy, ctx.Log) } - return s.SyncDownUpdate(ctx, vObj, newNetworkPolicy) + return s.SyncToHostUpdate(ctx, vObj, newNetworkPolicy) } diff --git a/pkg/controllers/resources/persistentvolumeclaims/syncer.go b/pkg/controllers/resources/persistentvolumeclaims/syncer.go index 8a1354e5f..e64bf534a 100644 --- a/pkg/controllers/resources/persistentvolumeclaims/syncer.go +++ b/pkg/controllers/resources/persistentvolumeclaims/syncer.go @@ -82,7 +82,7 @@ func (s *persistentVolumeClaimSyncer) SyncToHost(ctx *synccontext.SyncContext, v return ctrl.Result{}, err } - return s.SyncDownCreate(ctx, vObj, newPvc) + return s.SyncToHostCreate(ctx, vObj, newPvc) } func (s *persistentVolumeClaimSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -163,7 +163,7 @@ func (s *persistentVolumeClaimSyncer) Sync(ctx *synccontext.SyncContext, pObj cl translator.PrintChanges(pPvc, newPvc, ctx.Log) } - return s.SyncDownUpdate(ctx, vPvc, newPvc) + return s.SyncToHostUpdate(ctx, vPvc, newPvc) } func (s *persistentVolumeClaimSyncer) ensurePersistentVolume(ctx *synccontext.SyncContext, pObj *corev1.PersistentVolumeClaim, vObj *corev1.PersistentVolumeClaim, log loghelper.Logger) (bool, error) { diff --git a/pkg/controllers/resources/poddisruptionbudgets/syncer.go b/pkg/controllers/resources/poddisruptionbudgets/syncer.go index 664a00257..39e188527 100644 --- a/pkg/controllers/resources/poddisruptionbudgets/syncer.go +++ b/pkg/controllers/resources/poddisruptionbudgets/syncer.go @@ -20,7 +20,7 @@ type pdbSyncer struct { } 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))) + return pdb.SyncToHostCreate(ctx, vObj, pdb.translate(ctx.Context, vObj.(*policyv1.PodDisruptionBudget))) } func (pdb *pdbSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -31,5 +31,5 @@ func (pdb *pdbSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vOb translator.PrintChanges(pObj, newPDB, ctx.Log) } - return pdb.SyncDownUpdate(ctx, vObj, newPDB) + return pdb.SyncToHostUpdate(ctx, vObj, newPDB) } diff --git a/pkg/controllers/resources/pods/syncer.go b/pkg/controllers/resources/pods/syncer.go index 990c7b3b3..79ac2b884 100644 --- a/pkg/controllers/resources/pods/syncer.go +++ b/pkg/controllers/resources/pods/syncer.go @@ -220,7 +220,7 @@ func (s *podSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) return ctrl.Result{}, nil } - return s.SyncDownCreate(ctx, vPod, pPod) + return s.SyncToHostCreate(ctx, vPod, pPod) } func (s *podSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -348,7 +348,7 @@ func (s *podSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj translator.PrintChanges(pPod, updatedPod, ctx.Log) } - return s.SyncDownUpdate(ctx, vPod, updatedPod) + return s.SyncToHostUpdate(ctx, vPod, updatedPod) } func syncEphemeralContainers(vPod *corev1.Pod, pPod *corev1.Pod) bool { diff --git a/pkg/controllers/resources/secrets/syncer.go b/pkg/controllers/resources/secrets/syncer.go index 44995a190..2c8bdf574 100644 --- a/pkg/controllers/resources/secrets/syncer.go +++ b/pkg/controllers/resources/secrets/syncer.go @@ -108,7 +108,7 @@ func (s *secretSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj client.Obje return ctrl.Result{}, nil } - return s.SyncDownCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*corev1.Secret))) + return s.SyncToHostCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*corev1.Secret))) } func (s *secretSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -132,7 +132,7 @@ func (s *secretSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vO translator.PrintChanges(pObj, newSecret, ctx.Log) } - return s.SyncDownUpdate(ctx, vObj, newSecret) + return s.SyncToHostUpdate(ctx, vObj, newSecret) } func (s *secretSyncer) isSecretUsed(ctx *synccontext.SyncContext, vObj runtime.Object) (bool, error) { diff --git a/pkg/controllers/resources/serviceaccounts/syncer.go b/pkg/controllers/resources/serviceaccounts/syncer.go index 5fc91d69f..e34a06157 100644 --- a/pkg/controllers/resources/serviceaccounts/syncer.go +++ b/pkg/controllers/resources/serviceaccounts/syncer.go @@ -21,7 +21,7 @@ type serviceAccountSyncer struct { } 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))) + return s.SyncToHostCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*corev1.ServiceAccount))) } func (s *serviceAccountSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -31,5 +31,5 @@ func (s *serviceAccountSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Ob translator.PrintChanges(pObj, newServiceAccount, ctx.Log) } - return s.SyncDownUpdate(ctx, vObj, newServiceAccount) + return s.SyncToHostUpdate(ctx, vObj, newServiceAccount) } diff --git a/pkg/controllers/resources/services/syncer.go b/pkg/controllers/resources/services/syncer.go index 4ad072f52..e01481968 100644 --- a/pkg/controllers/resources/services/syncer.go +++ b/pkg/controllers/resources/services/syncer.go @@ -45,7 +45,7 @@ func (s *serviceSyncer) WithOptions() *syncertypes.Options { } 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))) + return s.SyncToHostCreate(ctx, vObj, s.translate(ctx.Context, vObj.(*corev1.Service))) } func (s *serviceSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -103,7 +103,7 @@ func (s *serviceSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, v translator.PrintChanges(pService, newService, ctx.Log) } - return s.SyncDownUpdate(ctx, vObj, newService) + return s.SyncToHostUpdate(ctx, vObj, newService) } func isSwitchingFromExternalName(pService *corev1.Service, vService *corev1.Service) bool { diff --git a/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer.go b/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer.go index b060592ae..bacba9ba5 100644 --- a/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer.go +++ b/pkg/controllers/resources/volumesnapshots/volumesnapshots/syncer.go @@ -60,7 +60,7 @@ func (s *volumeSnapshotSyncer) SyncToHost(ctx *synccontext.SyncContext, vObj cli return ctrl.Result{}, err } - return s.SyncDownCreate(ctx, vObj, pObj) + return s.SyncToHostCreate(ctx, vObj, pObj) } func (s *volumeSnapshotSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { @@ -153,5 +153,5 @@ func (s *volumeSnapshotSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Ob translator.PrintChanges(pVS, updated, ctx.Log) } - return s.SyncDownUpdate(ctx, vVS, updated) + return s.SyncToHostUpdate(ctx, vVS, updated) } diff --git a/pkg/controllers/syncer/syncer_test.go b/pkg/controllers/syncer/syncer_test.go index a5eb51940..b9025a708 100644 --- a/pkg/controllers/syncer/syncer_test.go +++ b/pkg/controllers/syncer/syncer_test.go @@ -49,12 +49,12 @@ 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) SyncToHost(ctx *synccontext.SyncContext, vObj client.Object) (ctrl.Result, error) { - return s.SyncDownCreate(ctx, vObj, s.naiveTranslateCreate(ctx, vObj)) + return s.SyncToHostCreate(ctx, vObj, s.naiveTranslateCreate(ctx, vObj)) } // Sync is called to sync a virtual object with a physical object func (s *mockSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object, vObj client.Object) (ctrl.Result, error) { - return s.SyncDownUpdate(ctx, vObj, s.naiveTranslateUpdate(ctx, vObj, pObj)) + return s.SyncToHostUpdate(ctx, vObj, s.naiveTranslateUpdate(ctx, vObj, pObj)) } var _ syncertypes.Syncer = &mockSyncer{} diff --git a/pkg/controllers/syncer/translator/namespaced_translator.go b/pkg/controllers/syncer/translator/namespaced_translator.go index 3ec07df4c..936ee777b 100644 --- a/pkg/controllers/syncer/translator/namespaced_translator.go +++ b/pkg/controllers/syncer/translator/namespaced_translator.go @@ -66,7 +66,7 @@ func (n *namespacedTranslator) RegisterIndices(ctx *context.RegisterContext) err }) } -func (n *namespacedTranslator) SyncDownCreate(ctx *context.SyncContext, vObj, pObj client.Object) (ctrl.Result, error) { +func (n *namespacedTranslator) SyncToHostCreate(ctx *context.SyncContext, vObj, pObj client.Object) (ctrl.Result, error) { ctx.Log.Infof("create physical %s %s/%s", n.name, pObj.GetNamespace(), pObj.GetName()) err := ctx.PhysicalClient.Create(ctx.Context, pObj) if err != nil { @@ -82,7 +82,7 @@ func (n *namespacedTranslator) SyncDownCreate(ctx *context.SyncContext, vObj, pO return ctrl.Result{}, nil } -func (n *namespacedTranslator) SyncDownUpdate(ctx *context.SyncContext, vObj, pObj client.Object) (ctrl.Result, error) { +func (n *namespacedTranslator) SyncToHostUpdate(ctx *context.SyncContext, vObj, pObj client.Object) (ctrl.Result, error) { // this is needed because of interface nil check if !(pObj == nil || (reflect.ValueOf(pObj).Kind() == reflect.Ptr && reflect.ValueOf(pObj).IsNil())) { ctx.Log.Infof("updating physical %s/%s, because virtual %s have changed", pObj.GetNamespace(), pObj.GetName(), n.name) diff --git a/pkg/controllers/syncer/translator/translator.go b/pkg/controllers/syncer/translator/translator.go index 1a73a9506..5173ada0a 100644 --- a/pkg/controllers/syncer/translator/translator.go +++ b/pkg/controllers/syncer/translator/translator.go @@ -51,12 +51,12 @@ type NamespacedTranslator interface { // RegisterIndices registers the default indices for the syncer RegisterIndices(ctx *syncercontext.RegisterContext) error - // SyncDownCreate creates the given pObj in the target namespace - SyncDownCreate(ctx *syncercontext.SyncContext, vObj, pObj client.Object) (ctrl.Result, error) + // SyncToHostCreate creates the given pObj in the target namespace + SyncToHostCreate(ctx *syncercontext.SyncContext, vObj, pObj client.Object) (ctrl.Result, error) - // SyncDownUpdate updates the given pObj (if not nil) in the target namespace - SyncDownUpdate(ctx *syncercontext.SyncContext, vObj, pObj client.Object) (ctrl.Result, error) + // SyncToHostUpdate updates the given pObj (if not nil) in the target namespace + SyncToHostUpdate(ctx *syncercontext.SyncContext, vObj, pObj client.Object) (ctrl.Result, error) - // Function to override default VirtualToHost name translation + // SetNameTranslator is a function to override default VirtualToHost name translation SetNameTranslator(nameTranslator translate.PhysicalNamespacedNameTranslator) }