@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "fmt"
2222
23+ "github.com/kcp-dev/logicalcluster/v3"
2324 "go.uber.org/zap"
2425
2526 "github.com/kcp-dev/api-syncagent/internal/mutation"
@@ -136,11 +137,16 @@ func NewResourceSyncer(
136137// Each of these steps can potentially end the current processing and return (true, nil). In this
137138// case, the caller should re-fetch the remote object and call Process() again (most likely in the
138139// next reconciliation). Only when (false, nil) is returned is the entire process finished.
139- func (s * ResourceSyncer ) Process (ctx context.Context , info clusterInfo , remoteObj * unstructured.Unstructured ) (requeue bool , err error ) {
140- log := s .log .With ("source-object" , newObjectKey (remoteObj , info .clusterName , info .workspacePath ))
140+ // The context must contain a cluster name and event recorder, optionally a workspace path.
141+ func (s * ResourceSyncer ) Process (ctx context.Context , remoteObj * unstructured.Unstructured ) (requeue bool , err error ) {
142+ clusterName := clusterFromContext (ctx )
143+ workspacePath := workspacePathFromContext (ctx )
144+ objectKey := newObjectKey (remoteObj , clusterName , workspacePath )
145+
146+ log := s .log .With ("source-object" , objectKey )
141147
142148 // find the local equivalent object in the local service cluster
143- localObj , err := s .findLocalObject (ctx , info , remoteObj )
149+ localObj , err := s .findLocalObject (ctx , objectKey )
144150 if err != nil {
145151 return false , fmt .Errorf ("failed to find local equivalent: %w" , err )
146152 }
@@ -151,8 +157,8 @@ func (s *ResourceSyncer) Process(ctx context.Context, info clusterInfo, remoteOb
151157 // Prepare object sync sides.
152158
153159 sourceSide := syncSide {
154- clusterName : info . clusterName ,
155- workspacePath : info . workspacePath ,
160+ clusterName : clusterName ,
161+ workspacePath : workspacePath ,
156162 client : s .remoteClient ,
157163 object : remoteObj ,
158164 }
@@ -172,7 +178,7 @@ func (s *ResourceSyncer) Process(ctx context.Context, info clusterInfo, remoteOb
172178 agentName : s .agentName ,
173179 subresources : s .subresources ,
174180 // use the projection and renaming rules configured in the PublishedResource
175- destCreator : s .newLocalObjectCreator (info ),
181+ destCreator : s .newLocalObjectCreator (clusterName , workspacePath ),
176182 // for the main resource, status subresource handling is enabled (this
177183 // means _allowing_ status back-syncing, it still depends on whether the
178184 // status subresource even exists whether an update happens)
@@ -210,8 +216,8 @@ func (s *ResourceSyncer) Process(ctx context.Context, info clusterInfo, remoteOb
210216 return s .processRelatedResources (ctx , log , stateStore , sourceSide , destSide )
211217}
212218
213- func (s * ResourceSyncer ) findLocalObject (ctx context.Context , info clusterInfo , remoteObj * unstructured. Unstructured ) (* unstructured.Unstructured , error ) {
214- localSelector := labels .SelectorFromSet (newObjectKey ( remoteObj , info . clusterName , info . workspacePath ) .Labels ())
219+ func (s * ResourceSyncer ) findLocalObject (ctx context.Context , objectKey objectKey ) (* unstructured.Unstructured , error ) {
220+ localSelector := labels .SelectorFromSet (objectKey .Labels ())
215221
216222 localObjects := & unstructured.UnstructuredList {}
217223 localObjects .SetAPIVersion (s .destDummy .GetAPIVersion ())
@@ -234,7 +240,7 @@ func (s *ResourceSyncer) findLocalObject(ctx context.Context, info clusterInfo,
234240 }
235241}
236242
237- func (s * ResourceSyncer ) newLocalObjectCreator (info clusterInfo ) objectCreatorFunc {
243+ func (s * ResourceSyncer ) newLocalObjectCreator (clusterName logicalcluster. Name , workspacePath logicalcluster. Path ) objectCreatorFunc {
238244 return func (remoteObj * unstructured.Unstructured ) (* unstructured.Unstructured , error ) {
239245 // map from the remote API into the actual, local API group
240246 destObj := remoteObj .DeepCopy ()
@@ -244,7 +250,7 @@ func (s *ResourceSyncer) newLocalObjectCreator(info clusterInfo) objectCreatorFu
244250 destScope := syncagentv1alpha1 .ResourceScope (s .localCRD .Spec .Scope )
245251
246252 // map namespace/name
247- mappedName , err := templating .GenerateLocalObjectName (s .pubRes , remoteObj , info . clusterName , info . workspacePath )
253+ mappedName , err := templating .GenerateLocalObjectName (s .pubRes , remoteObj , clusterName , workspacePath )
248254 if err != nil {
249255 return nil , fmt .Errorf ("failed to generate local object name: %w" , err )
250256 }
0 commit comments