Skip to content

Commit

Permalink
add PendingPopulation DataVolume phase (#2729)
Browse files Browse the repository at this point in the history
* add PendingPopulation DataVolume phase

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* add IsSucceededOrPendingPopulation helper to replace a call to IsPopulated

IsPopulated still valid and used elsewhere

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

---------

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
  • Loading branch information
mhenriks committed May 26, 2023
1 parent 2cf1ef2 commit fae6535
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ const (

// WaitForFirstConsumer represents a data volume with a current phase of WaitForFirstConsumer
WaitForFirstConsumer DataVolumePhase = "WaitForFirstConsumer"
// PendingPopulation represents a data volume which should be populated by
// the CDI populators but haven't created the pvc' yet
PendingPopulation DataVolumePhase = "PendingPopulation"

// Succeeded represents a DataVolumePhase of Succeeded
Succeeded DataVolumePhase = "Succeeded"
Expand Down
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 fae6535

Please sign in to comment.