@@ -52,7 +52,7 @@ import (
5252 "github.com/fluxcd/pkg/runtime/acl"
5353 runtimeClient "github.com/fluxcd/pkg/runtime/client"
5454 "github.com/fluxcd/pkg/runtime/conditions"
55- helper "github.com/fluxcd/pkg/runtime/controller"
55+ runtimeCtrl "github.com/fluxcd/pkg/runtime/controller"
5656 "github.com/fluxcd/pkg/runtime/events"
5757 "github.com/fluxcd/pkg/runtime/patch"
5858 "github.com/fluxcd/pkg/runtime/predicates"
@@ -78,7 +78,7 @@ import (
7878type KustomizationReconciler struct {
7979 client.Client
8080 kuberecorder.EventRecorder
81- helper .Metrics
81+ runtimeCtrl .Metrics
8282
8383 artifactFetcher * fetch.ArchiveFetcher
8484 requeueDependency time.Duration
@@ -165,7 +165,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
165165 return ctrl.Result {}, client .IgnoreNotFound (err )
166166 }
167167
168- // Initialize the patch helper with the current version of the object.
168+ // Initialize the runtime patcher with the current version of the object.
169169 patcher := patch .NewSerialPatcher (obj , r .Client )
170170
171171 // Finalise the reconciliation and report the results.
@@ -206,11 +206,6 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
206206 return ctrl.Result {}, nil
207207 }
208208
209- // Set reconciling condition.
210- if obj .Generation != obj .Status .ObservedGeneration {
211- conditions .MarkReconciling (obj , meta .ProgressingReason , "Reconciling new object generation (%d)" , obj .Generation )
212- }
213-
214209 // Resolve the source reference and requeue the reconciliation if the source is not found.
215210 artifactSource , err := r .getSource (ctx , obj )
216211 if err != nil {
@@ -253,14 +248,6 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
253248 log .Info ("All dependencies are ready, proceeding with reconciliation" )
254249 }
255250
256- // Set the reconciliation status to progressing.
257- progressingMsg := fmt .Sprintf ("Reconciling revision %s with a timeout of %s" ,
258- artifactSource .GetArtifact ().Revision , obj .GetTimeout ().String ())
259- conditions .MarkReconciling (obj , meta .ProgressingReason , progressingMsg )
260- if err := r .patch (ctx , obj , patcher ); err != nil {
261- return ctrl.Result {Requeue : true }, err
262- }
263-
264251 // Reconcile the latest revision.
265252 reconcileErr := r .reconcile (ctx , obj , artifactSource , patcher )
266253
@@ -294,18 +281,23 @@ func (r *KustomizationReconciler) reconcile(
294281 src sourcev1.Source ,
295282 patcher * patch.SerialPatcher ) error {
296283
284+ revision := src .GetArtifact ().Revision
285+ isNewRevision := obj .Status .LastAppliedRevision != revision
286+
287+ // Update status with the reconciliation progress.
288+ progressingMsg := fmt .Sprintf ("Fetching manifests for revision %s with a timeout of %s" , revision , obj .GetTimeout ().String ())
289+ conditions .MarkUnknown (obj , meta .ReadyCondition , meta .ProgressingReason , "Reconciliation in progress" )
290+ conditions .MarkReconciling (obj , meta .ProgressingReason , progressingMsg )
291+ if err := r .patch (ctx , obj , patcher ); err != nil {
292+ return fmt .Errorf ("failed to update status, error: %w" , err )
293+ }
294+
297295 // Create a snapshot of the current inventory.
298296 oldInventory := inventory .New ()
299297 if obj .Status .Inventory != nil {
300298 obj .Status .Inventory .DeepCopyInto (oldInventory )
301299 }
302300
303- revision := src .GetArtifact ().Revision
304- isNewRevision := obj .Status .LastAppliedRevision != revision
305-
306- // Set last attempted revision in status.
307- obj .Status .LastAttemptedRevision = revision
308-
309301 // Create tmp dir.
310302 tmpDir , err := MkdirTempAbs ("" , "kustomization-" )
311303 if err != nil {
@@ -329,12 +321,21 @@ func (r *KustomizationReconciler) reconcile(
329321 conditions .MarkFalse (obj , meta .ReadyCondition , kustomizev1 .ArtifactFailedReason , err .Error ())
330322 return err
331323 }
324+
332325 if _ , err := os .Stat (dirPath ); err != nil {
333326 err = fmt .Errorf ("kustomization path not found: %w" , err )
334327 conditions .MarkFalse (obj , meta .ReadyCondition , kustomizev1 .ArtifactFailedReason , err .Error ())
335328 return err
336329 }
337330
331+ // Report progress and set last attempted revision in status.
332+ obj .Status .LastAttemptedRevision = revision
333+ progressingMsg = fmt .Sprintf ("Building manifests for revision %s with a timeout of %s" , revision , obj .GetTimeout ().String ())
334+ conditions .MarkReconciling (obj , meta .ProgressingReason , progressingMsg )
335+ if err := r .patch (ctx , obj , patcher ); err != nil {
336+ return fmt .Errorf ("failed to update status, error: %w" , err )
337+ }
338+
338339 // Configure the Kubernetes client for impersonation.
339340 impersonation := runtimeClient .NewImpersonator (
340341 r .Client ,
@@ -382,6 +383,13 @@ func (r *KustomizationReconciler) reconcile(
382383 })
383384 resourceManager .SetOwnerLabels (objects , obj .GetName (), obj .GetNamespace ())
384385
386+ // Update status with the reconciliation progress.
387+ progressingMsg = fmt .Sprintf ("Detecting drift for revision %s with a timeout of %s" , revision , obj .GetTimeout ().String ())
388+ conditions .MarkReconciling (obj , meta .ProgressingReason , progressingMsg )
389+ if err := r .patch (ctx , obj , patcher ); err != nil {
390+ return fmt .Errorf ("failed to update status, error: %w" , err )
391+ }
392+
385393 // Validate and apply resources in stages.
386394 drifted , changeSet , err := r .apply (ctx , resourceManager , obj , revision , objects )
387395 if err != nil {
@@ -798,7 +806,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
798806 return nil
799807 }
800808
801- // guard against deadlock (waiting on itself)
809+ // Guard against deadlock (waiting on itself).
802810 var toCheck []object.ObjMetadata
803811 for _ , o := range objects {
804812 if o .GroupKind .Kind == kustomizev1 .KustomizationKind &&
@@ -809,18 +817,18 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
809817 toCheck = append (toCheck , o )
810818 }
811819
812- // find the previous health check result
820+ // Find the previous health check result.
813821 wasHealthy := apimeta .IsStatusConditionTrue (obj .Status .Conditions , kustomizev1 .HealthyCondition )
814822
815- // set the Healthy and Ready conditions to progressing
816- message := fmt .Sprintf ("Running health checks with a timeout of %s" , obj .GetTimeout ().String ())
823+ // Update status with the reconciliation progress.
824+ message := fmt .Sprintf ("Running health checks for revision %s with a timeout of %s" , revision , obj .GetTimeout ().String ())
817825 conditions .MarkReconciling (obj , meta .ProgressingReason , message )
818826 conditions .MarkUnknown (obj , kustomizev1 .HealthyCondition , meta .ProgressingReason , message )
819827 if err := r .patch (ctx , obj , patcher ); err != nil {
820828 return fmt .Errorf ("unable to update the healthy status to progressing, error: %w" , err )
821829 }
822830
823- // check the health with a default timeout of 30sec shorter than the reconciliation interval
831+ // Check the health with a default timeout of 30sec shorter than the reconciliation interval.
824832 if err := manager .WaitForSet (toCheck , ssa.WaitOptions {
825833 Interval : 5 * time .Second ,
826834 Timeout : obj .GetTimeout (),
@@ -830,7 +838,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
830838 return fmt .Errorf ("Health check failed after %s: %w" , time .Since (checkStart ).String (), err )
831839 }
832840
833- // emit event if the previous health check failed
841+ // Emit recovery event if the previous health check failed.
834842 msg := fmt .Sprintf ("Health check passed in %s" , time .Since (checkStart ).String ())
835843 if ! wasHealthy || (isNewRevision && drifted ) {
836844 r .event (obj , revision , events .EventSeverityInfo , msg , nil )
@@ -998,7 +1006,7 @@ func (r *KustomizationReconciler) patch(ctx context.Context,
9981006 obj * kustomizev1.Kustomization ,
9991007 patcher * patch.SerialPatcher ) (retErr error ) {
10001008
1001- // Configure the patch helper .
1009+ // Configure the runtime patcher .
10021010 patchOpts := []patch.Option {}
10031011 ownedConditions := []string {
10041012 kustomizev1 .HealthyCondition ,
0 commit comments