Skip to content

Commit

Permalink
Fix CSI & Smart clones with WFFC storage status reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
  • Loading branch information
akalenyu committed Jul 20, 2022
1 parent 9df7141 commit 6ca7192
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions pkg/controller/datavolume-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ func (r *DatavolumeReconciler) Reconcile(_ context.Context, req reconcile.Reques
} else if err != nil {
return reconcile.Result{}, err
}

} else {
res, err := r.garbageCollect(datavolume, pvc, log)
if err != nil {
Expand Down Expand Up @@ -733,6 +732,11 @@ func (r *DatavolumeReconciler) reconcileClone(log logr.Logger,
pvc = newPvc
}

shouldBeMarkedWaitForFirstConsumer, err := r.shouldBeMarkedWaitForFirstConsumer(pvc)
if err != nil {
return reconcile.Result{}, err
}

switch selectedCloneStrategy {
case HostAssistedClone:
if !pvcPopulated {
Expand All @@ -747,7 +751,10 @@ func (r *DatavolumeReconciler) reconcileClone(log logr.Logger,
return reconcile.Result{}, err
}
case corev1.ClaimPending:
return reconcile.Result{}, r.updateCloneStatusPhase(cdiv1.CSICloneInProgress, datavolume, pvc, selectedCloneStrategy)
r.log.V(3).Info("ClaimPending CSIClone")
if !shouldBeMarkedWaitForFirstConsumer {
return reconcile.Result{}, r.updateCloneStatusPhase(cdiv1.CSICloneInProgress, datavolume, pvc, selectedCloneStrategy)
}
case corev1.ClaimLost:
return reconcile.Result{},
r.updateDataVolumeStatusPhaseWithEvent(cdiv1.Failed, datavolume, pvc, selectedCloneStrategy,
Expand All @@ -759,7 +766,7 @@ func (r *DatavolumeReconciler) reconcileClone(log logr.Logger,
}
fallthrough
case SmartClone:
if !pvcPopulated {
if !pvcPopulated && !shouldBeMarkedWaitForFirstConsumer {
return r.finishClone(log, datavolume, pvc, pvcSpec, transferName, selectedCloneStrategy)
}
}
Expand Down Expand Up @@ -912,7 +919,7 @@ func (r *DatavolumeReconciler) reconcileCsiClonePvc(log logr.Logger,
r.updateCloneStatusPhase(cdiv1.CloneScheduled, datavolume, nil, CsiClone)
}

log.Info("Creating PVC for datavolume")
log.Info("reconcileCsiClonePvc: Creating PVC for datavolume")
cloneTargetPvc, err := r.newVolumeClonePVC(datavolume, sourcePvc, pvcSpec, pvcName)
if err != nil {
return reconcile.Result{}, err
Expand Down Expand Up @@ -2211,14 +2218,11 @@ func (r *DatavolumeReconciler) updateUploadStatusPhase(pvc *corev1.PersistentVol
func (r *DatavolumeReconciler) reconcileDataVolumeStatus(dataVolume *cdiv1.DataVolume, pvc *corev1.PersistentVolumeClaim, selectedCloneStrategy cloneStrategy) (reconcile.Result, error) {
dataVolumeCopy := dataVolume.DeepCopy()
var event DataVolumeEvent
var err error
result := reconcile.Result{}

curPhase := dataVolumeCopy.Status.Phase
if pvc != nil {
storageClassBindingMode, err := r.getStorageClassBindingMode(pvc.Spec.StorageClassName)
if err != nil {
return reconcile.Result{}, err
}
dataVolumeCopy.Status.ClaimName = pvc.Name

// the following check is for a case where the request is to create a blank disk for a block device.
Expand Down Expand Up @@ -2270,19 +2274,17 @@ func (r *DatavolumeReconciler) reconcileDataVolumeStatus(dataVolume *cdiv1.DataV
}
} else {
dataVolumeCopy.Status.Phase = cdiv1.Succeeded

}
r.updateImportStatusPhase(pvc, dataVolumeCopy, &event)
}
} else {
switch pvc.Status.Phase {
case corev1.ClaimPending:
honorWaitForFirstConsumerEnabled, err := r.featureGates.HonorWaitForFirstConsumerEnabled()
shouldBeMarkedWaitForFirstConsumer, err := r.shouldBeMarkedWaitForFirstConsumer(pvc)
if err != nil {
return reconcile.Result{}, err
}
if honorWaitForFirstConsumerEnabled &&
*storageClassBindingMode == storagev1.VolumeBindingWaitForFirstConsumer {
if shouldBeMarkedWaitForFirstConsumer {
dataVolumeCopy.Status.Phase = cdiv1.WaitForFirstConsumer
} else {
dataVolumeCopy.Status.Phase = cdiv1.Pending
Expand Down Expand Up @@ -2889,6 +2891,25 @@ func (r *DatavolumeReconciler) isSourceReadyToClone(
return true, nil
}

// shouldBeMarkedWaitForFirstConsumer decided whether we should mark DV as WFFC
func (r *DatavolumeReconciler) shouldBeMarkedWaitForFirstConsumer(pvc *corev1.PersistentVolumeClaim) (bool, error) {
storageClassBindingMode, err := r.getStorageClassBindingMode(pvc.Spec.StorageClassName)
if err != nil {
return false, err
}

honorWaitForFirstConsumerEnabled, err := r.featureGates.HonorWaitForFirstConsumerEnabled()
if err != nil {
return false, err
}

res := honorWaitForFirstConsumerEnabled &&
storageClassBindingMode != nil && *storageClassBindingMode == storagev1.VolumeBindingWaitForFirstConsumer &&
pvc.Status.Phase == corev1.ClaimPending

return res, nil
}

// detectCloneSize obtains and assigns the original PVC's size when cloning using an empty storage value
func (r *DatavolumeReconciler) detectCloneSize(
dv *cdiv1.DataVolume,
Expand Down

0 comments on commit 6ca7192

Please sign in to comment.