Skip to content

Commit

Permalink
add IsSucceededOrPendingPopulation helper to replace a call to IsPopu…
Browse files Browse the repository at this point in the history
…lated

IsPopulated still valid and used elsewhere

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
  • Loading branch information
mhenriks committed May 25, 2023
1 parent 17d88a7 commit 30c1631
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ func IsPopulated(pvc *corev1.PersistentVolumeClaim, getDvFunc func(name, namespa
return true, nil
}

// IsSucceededOrPendingPopulation indicates if the persistent volume passed in has been fully populated or is waiting for a consumer.
// It follow the following logic
// 1. If the PVC is not owned by a DataVolume, return true, we assume someone else has properly populated the image
// 2. If the PVC is owned by a DataVolume, look up the DV and check the phase, if phase succeeded or pending population return true
// 3. If the PVC is owned by a DataVolume, look up the DV and check the phase, if phase !succeeded return false
func IsSucceededOrPendingPopulation(pvc *corev1.PersistentVolumeClaim, getDvFunc func(name, namespace string) (*DataVolume, error)) (bool, error) {
pvcOwner := metav1.GetControllerOf(pvc)
if pvcOwner != nil && pvcOwner.Kind == "DataVolume" {
// Find the data volume:
dv, err := getDvFunc(pvcOwner.Name, pvc.Namespace)
if err != nil {
return false, err
}
return dv.Status.Phase == Succeeded || dv.Status.Phase == PendingPopulation, nil
}
return true, nil
}

// IsWaitForFirstConsumerBeforePopulating indicates if the persistent volume passed in is in ClaimPending state and waiting for first consumer.
// It follow the following logic
// 1. If the PVC is not owned by a DataVolume, return false, we can not assume it will be populated
Expand Down

0 comments on commit 30c1631

Please sign in to comment.