// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
// the KVMCluster object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile
Reconcile is part of the main kubernetes reconciliation loop which aims to
move the current state of the cluster closer to the desired state.
TODO(user): Modify the Reconcile function to compare the state specified by
the KVMCluster object against the actual cluster state, and then
perform operations to make the cluster state reflect the state specified by
the user.


// Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state . // TODO ( user ) : Modify the Reconcile function to compare the state specified by // the KVMCluster object against the actual cluster state and then // perform operations to make the cluster state reflect the state specified by // the user . // // For more details check Reconcile and its Result here : // - https : // pkg . go . dev / sigs . k8s . io / controller - runtime@v0 . 8 . 3 / pkg / reconcile
func (r *KVMClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reconcileError error) {
	log := ctrl.LoggerFrom(ctx)
	kvmCluster := &v1alpha4.KVMCluster{}
	err := r.Get(ctx, req.NamespacedName, kvmCluster)
	if err != nil {
		if apierrors.IsNotFound(err) {
			return reconcile.Result{}, nil
		}
		return reconcile.Result{}, err
	}
	defer func() {
		if reconcileError != nil {
			r.Recorder.Event(kvmCluster, "Warning", "failed-to-reconcile", reconcileError.Error())
			return
		}
		metrics.CaptureLastReconciled(KVMClusterController)
	}()
	cluster, err := util.GetOwnerCluster(ctx, r.Client, kvmCluster.ObjectMeta)
	if err != nil {
		return reconcile.Result{}, err
	}
	if cluster == nil {
		log.Info("Cluster Controller has not yet set OwnerRef")
		return reconcile.Result{}, nil
	}
	if annotations.IsPaused(cluster, kvmCluster) {
		log.Info("KVMCluster or linked Cluster is marked as paused. Won't reconcile")
		return reconcile.Result{}, nil
	}
	clusterScope, err := scope.NewClusterScope(scope.ClusterScopeParams{
		Client:         r.Client,
		Cluster:        cluster,
		Logger:         log,
		KVMCluster:     kvmCluster,
		ControllerName: KVMClusterController,
	})
	if err != nil {
		return reconcile.Result{}, errors.Errorf("failed to create scope: %+v", err)
	}
	defer func() {
		if err := clusterScope.Close(); err != nil && reconcileError == nil {
			reconcileError = err
		}
	}()
	if !kvmCluster.DeletionTimestamp.IsZero() {
		return r.reconcileDelete(ctx, clusterScope)
	}
	return r.reconcileNormal(ctx, clusterScope)
}
func ( r * KVMClusterReconciler ) Reconcile ( ctx context . Context , req ctrl . Request ) ( _ ctrl . Result , reconcileError error ) { log := ctrl . LoggerFrom ( ctx ) kvmCluster := & v1alpha4 . KVMCluster { } err := r . Get ( ctx , req . NamespacedName , kvmCluster ) if err != nil { if apierrors . IsNotFound ( err ) { return reconcile . Result { } , nil } return reconcile . Result { } , err } defer func ( ) { if reconcileError != nil { r . Recorder . Event ( kvmCluster , " " , " " , reconcileError . Error ( ) ) return } metrics . CaptureLastReconciled ( KVMClusterController ) } ( ) cluster , err := util . GetOwnerCluster ( ctx , r . Client , kvmCluster . ObjectMeta ) if err != nil { return reconcile . Result { } , err } if cluster == nil { log . Info ( " " ) return reconcile . Result { } , nil } if annotations . IsPaused ( cluster , kvmCluster ) { log . Info ( " " ) return reconcile . Result { } , nil } clusterScope , err := scope . NewClusterScope ( scope . ClusterScopeParams { Client : r . Client , Cluster : cluster , Logger : log , KVMCluster : kvmCluster , ControllerName : KVMClusterController , } ) if err != nil { return reconcile . Result { } , errors . Errorf ( " " , err ) } defer func ( ) { if err := clusterScope . Close ( ) ; err != nil && reconcileError == nil { reconcileError = err } } ( ) if ! kvmCluster . DeletionTimestamp . IsZero ( ) { return r . reconcileDelete ( ctx , clusterScope ) } return r . reconcileNormal ( ctx , clusterScope ) }
Reconcile is part of the main kubernetes reconciliation loop which aims to
move the current state of the cluster closer to the desired state.
Reconcile is part of the main kubernetes reconciliation loop which aims to move the current state of the cluster closer to the desired state .
// Fetch the KVMCluster instance // Fetch the Cluster. // log = log.WithValues("cluster", cluster.Name) // Create the scope. // Always close the scope when exiting this function so we can persist any KVMCluster changes. // Handle deleted clusters // Handle non-deleted clusters