Skip to content

Commit

Permalink
Always set a valid ContentType for created PVC (#2409)
Browse files Browse the repository at this point in the history
When DV is garbage collected and PVC ContentType is not correctly set,
there is no way to guess the PVC ContetType. In CDI we assume that if
there is no content type it's a kubevirt disk, but is other cases
(e.g. export) we cannot make that assumption.

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
  • Loading branch information
arnongilboa committed Aug 25, 2022
1 parent 48e9694 commit 9a839ae
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/controller/datavolume-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2582,14 +2582,12 @@ func (r *DatavolumeReconciler) newPersistentVolumeClaim(dataVolume *cdiv1.DataVo
}

annotations[AnnPodRestarts] = "0"
annotations[AnnContentType] = string(getContentType(dataVolume))

if dataVolume.Spec.Source.HTTP != nil {
annotations[AnnEndpoint] = dataVolume.Spec.Source.HTTP.URL
annotations[AnnSource] = SourceHTTP
if dataVolume.Spec.ContentType == cdiv1.DataVolumeArchive {
annotations[AnnContentType] = string(cdiv1.DataVolumeArchive)
} else {
annotations[AnnContentType] = string(cdiv1.DataVolumeKubeVirt)
}

if dataVolume.Spec.Source.HTTP.SecretRef != "" {
annotations[AnnSecret] = dataVolume.Spec.Source.HTTP.SecretRef
}
Expand Down Expand Up @@ -2627,7 +2625,6 @@ func (r *DatavolumeReconciler) newPersistentVolumeClaim(dataVolume *cdiv1.DataVo
annotations[AnnRegistryImageStream] = "true"
}
}
annotations[AnnContentType] = string(dataVolume.Spec.ContentType)
secretRef := dataVolume.Spec.Source.Registry.SecretRef
if secretRef != nil && *secretRef != "" {
annotations[AnnSecret] = *secretRef
Expand All @@ -2649,10 +2646,8 @@ func (r *DatavolumeReconciler) newPersistentVolumeClaim(dataVolume *cdiv1.DataVo
annotations[AnnCloneRequest] = sourceNamespace + "/" + dataVolume.Spec.Source.PVC.Name
} else if dataVolume.Spec.Source.Upload != nil {
annotations[AnnUploadRequest] = ""
annotations[AnnContentType] = string(dataVolume.Spec.ContentType)
} else if dataVolume.Spec.Source.Blank != nil {
annotations[AnnSource] = SourceNone
annotations[AnnContentType] = string(cdiv1.DataVolumeKubeVirt)
} else if dataVolume.Spec.Source.Imageio != nil {
annotations[AnnEndpoint] = dataVolume.Spec.Source.Imageio.URL
annotations[AnnSource] = SourceImageio
Expand Down Expand Up @@ -2705,6 +2700,13 @@ func (r *DatavolumeReconciler) newPersistentVolumeClaim(dataVolume *cdiv1.DataVo
return pvc, nil
}

func getContentType(dv *cdiv1.DataVolume) cdiv1.DataVolumeContentType {
if dv.Spec.ContentType == cdiv1.DataVolumeArchive {
return cdiv1.DataVolumeArchive
}
return cdiv1.DataVolumeKubeVirt
}

// If sourceRef is set, populate spec.Source with data from the DataSource
func (r *DatavolumeReconciler) populateSourceIfSourceRef(dv *cdiv1.DataVolume) error {
if dv.Spec.SourceRef == nil {
Expand Down

0 comments on commit 9a839ae

Please sign in to comment.