@@ -100,16 +100,23 @@ func (c *SyncController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
100100 instance .Status .LastSyncError = ptr .To (errList [0 ].Error ())
101101 instance .Status .LastSyncTime = & metav1.Time {Time : time .Now ()}
102102 log .Error (errList [0 ], "failed to sync resources" )
103+
104+ if err := c .updateStatus (ctx , instance ); err != nil {
105+ return requeueAfter (10 * time .Second , err )
106+ }
107+ return noRequeue ()
103108 }
104109
105- err = c .reconcile ( ctx , instance )
110+ syncedData , err : = c .ResourceParser . Diff ( )
106111 if err != nil {
107- log .Error (err , "failed to reconcile" )
108112 return noRequeue ()
109113 }
110114
115+ instance .Status .SyncedData = ptr .To (string (syncedData ))
116+
111117 if c .shouldEnqueueData (instance ) {
112118 instance .Status .SyncedDataHash = ptr .To (hash (instance .Status .SyncedData ))
119+ instance .Status .LastSyncTime = & metav1.Time {Time : time .Now ()}
113120 if err := c .enqueueData (instance ); err != nil {
114121 log .Error (err , "failed to enqueue message" )
115122 if err := c .updateStatus (ctx , instance ); err != nil {
@@ -257,28 +264,6 @@ func (c *SyncController) enqueueRequestsFromMapFunc(gvk schema.GroupVersionKind)
257264 }
258265}
259266
260- // reconcile merges the provided patch with the initial data and updates the status of the ClusterSync object
261- func (c * SyncController ) reconcile (ctx context.Context , instance * registryv1alpha1.ClusterSync ) error {
262- syncedData , err := c .ResourceParser .Diff ()
263- if err != nil {
264- return err
265- }
266-
267- instance .Status .SyncedData = ptr .To (string (syncedData ))
268-
269- if ! c .hasDifferentHash (instance ) {
270- c .Log .Info ("no data changes detected" ,
271- "name" , instance .GetName (),
272- "namespace" , instance .GetNamespace ())
273- return nil
274- }
275-
276- instance .Status .SyncedDataHash = ptr .To (hash (instance .Status .SyncedData ))
277- instance .Status .LastSyncTime = & metav1.Time {Time : time .Now ()}
278-
279- return c .updateStatus (ctx , instance )
280- }
281-
282267func (c * SyncController ) enqueueData (instance * registryv1alpha1.ClusterSync ) error {
283268 ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
284269 defer cancel ()
@@ -318,7 +303,7 @@ func (c *SyncController) enqueueData(instance *registryv1alpha1.ClusterSync) err
318303}
319304
320305func (c * SyncController ) shouldEnqueueData (instance * registryv1alpha1.ClusterSync ) bool {
321- return c .isLastSyncSuccessful (instance )
306+ return c .isLastSyncSuccessful (instance ) && c . hasDifferentHash ( instance )
322307}
323308
324309func (c * SyncController ) hasDifferentHash (object runtime.Object ) bool {
0 commit comments