// Reconcile performs the reconciling for a single named ProgressiveSync object
Reconcile performs the reconciling for a single named ProgressiveSync object
// Reconcile performs the reconciling for a single named ProgressiveSync object
func (r *ProgressiveSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	log := r.Log.WithValues("progressivesync", req.NamespacedName)
	log.Info("reconciliation loop started")
	var ps syncv1alpha1.ProgressiveSync
	if err := r.Get(ctx, req.NamespacedName, &ps); err != nil {
		log.Error(err, "unable to fetch progressivesync object")
		return ctrl.Result{}, client.IgnoreNotFound(err)
	}
	log = log.WithValues("applicationset", ps.Spec.SourceRef.Name)
	if !ps.ObjectMeta.DeletionTimestamp.IsZero() {
		controllerutil.RemoveFinalizer(&ps, syncv1alpha1.ProgressiveSyncFinalizer)
		if err := r.Update(ctx, &ps); err != nil {
			log.Error(err, "failed to update object when removing finalizer")
			return ctrl.Result{}, err
		}
		return ctrl.Result{}, nil
	}
	if !controllerutil.ContainsFinalizer(&ps, syncv1alpha1.ProgressiveSyncFinalizer) {
		controllerutil.AddFinalizer(&ps, syncv1alpha1.ProgressiveSyncFinalizer)
		if err := r.Update(ctx, &ps); err != nil {
			log.Error(err, "failed to update object when adding finalizer")
			return ctrl.Result{}, err
		}
		return ctrl.Result{Requeue: true}, nil
	}
	pss, _ := r.StateManager.Get(ps.Name)
	newHash, err := r.calculateHashedSpec(ctx, &ps)
	if err != nil {
		log.Error(err, "Failed to generate the hash value from the ApplicationSet spec")
		return ctrl.Result{}, err
	}
	currentHash := pss.GetHashedSpec()
	if currentHash != newHash {
		pss.SetHashedSpec(newHash)
		log.Info("Successfully updated the hash value of the ApplicationSet spec", "service", ps.Name)
	} else {
		log.Info("Hash value is the same as nothing has changed in the ApplicationSet spec", "service", ps.Name)
	}
	latest := ps
	var result reconcile.Result
	var reconcileErr error
	for _, stage := range ps.Spec.Stages {
		log = log.WithValues("stage", stage.Name)
		latest, result, reconcileErr = r.reconcileStage(ctx, latest, stage, pss)
		if err := r.updateStatusWithRetry(ctx, &latest); err != nil {
			return ctrl.Result{}, err
		}
		if result.Requeue || reconcileErr != nil {
			log.Info("requeuing stage")
			return result, reconcileErr
		}
	}
	completed := latest.NewStatusCondition(syncv1alpha1.CompletedCondition, metav1.ConditionTrue, syncv1alpha1.StagesCompleteReason, "All stages completed")
	apimeta.SetStatusCondition(latest.GetStatusConditions(), completed)
	if err := r.updateStatusWithRetry(ctx, &latest); err != nil {
		log.Error(err, "failed to update object status")
		return ctrl.Result{}, err
	}
	log.Info("sync completed")
	return ctrl.Result{}, nil
}
func ( r * ProgressiveSyncReconciler ) Reconcile ( ctx context . Context , req ctrl . Request ) ( ctrl . Result , error ) { log := r . Log . WithValues ( " " , req . NamespacedName ) log . Info ( " " ) var ps syncv1alpha1 . ProgressiveSync if err := r . Get ( ctx , req . NamespacedName , & ps ) ; err != nil { log . Error ( err , " " ) return ctrl . Result { } , client . IgnoreNotFound ( err ) } log = log . WithValues ( " " , ps . Spec . SourceRef . Name ) if ! ps . ObjectMeta . DeletionTimestamp . IsZero ( ) { controllerutil . RemoveFinalizer ( & ps , syncv1alpha1 . ProgressiveSyncFinalizer ) if err := r . Update ( ctx , & ps ) ; err != nil { log . Error ( err , " " ) return ctrl . Result { } , err } return ctrl . Result { } , nil } if ! controllerutil . ContainsFinalizer ( & ps , syncv1alpha1 . ProgressiveSyncFinalizer ) { controllerutil . AddFinalizer ( & ps , syncv1alpha1 . ProgressiveSyncFinalizer ) if err := r . Update ( ctx , & ps ) ; err != nil { log . Error ( err , " " ) return ctrl . Result { } , err } return ctrl . Result { Requeue : true } , nil } pss , _ := r . StateManager . Get ( ps . Name ) newHash , err := r . calculateHashedSpec ( ctx , & ps ) if err != nil { log . Error ( err , " " ) return ctrl . Result { } , err } currentHash := pss . GetHashedSpec ( ) if currentHash != newHash { pss . SetHashedSpec ( newHash ) log . Info ( " " , " " , ps . Name ) } else { log . Info ( " " , " " , ps . Name ) } latest := ps var result reconcile . Result var reconcileErr error for _ , stage := range ps . Spec . Stages { log = log . WithValues ( " " , stage . Name ) latest , result , reconcileErr = r . reconcileStage ( ctx , latest , stage , pss ) if err := r . updateStatusWithRetry ( ctx , & latest ) ; err != nil { return ctrl . Result { } , err } if result . Requeue || reconcileErr != nil { log . Info ( " " ) return result , reconcileErr } } completed := latest . NewStatusCondition ( syncv1alpha1 . CompletedCondition , metav1 . ConditionTrue , syncv1alpha1 . StagesCompleteReason , " " ) apimeta . SetStatusCondition ( latest . GetStatusConditions ( ) , completed ) if err := r . updateStatusWithRetry ( ctx , & latest ) ; err != nil { log . Error ( err , " " ) return ctrl . Result { } , err } log . Info ( " " ) return ctrl . Result { } , nil }
Reconcile performs the reconciling for a single named ProgressiveSync object
Reconcile performs the reconciling for a single named ProgressiveSync object
// Get the ProgressiveSync object // If the object is being deleted, remove finalizer and don't requeue it // Stop reconciliation as the item is being deleted // Add finalizer if it doesn't exist // Requeue after adding the finalizer // Progressive sync completed