Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always set a valid ContentType for created PVC #2409

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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