mirror of
https://github.com/kubevirt/containerized-data-importer.git
synced 2025-06-03 06:30:22 +00:00
Rename PVC webhook rendering label to applyStorageProfile (#3124)
Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
This commit is contained in:
parent
adc4abacaf
commit
56a7eaeebc
@ -26,7 +26,7 @@ spec:
|
||||
|
||||
## Usage
|
||||
|
||||
For any PVC you want to use `StorageProfile` mutating webhook rendering, label it with `cdi.kubevirt.io/useStorageProfile: "true"`
|
||||
For any PVC you want to use `StorageProfile` mutating webhook rendering, label it with `cdi.kubevirt.io/applyStorageProfile: "true"`
|
||||
|
||||
If you want to use `volumeMode` preferred by CDI according to `StorageProfiles`, set it to `FromStorageProfile`. Otherwise if not explicitly set to `Block`, it will be `Filesystem` by k8s default.
|
||||
|
||||
@ -40,7 +40,7 @@ kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: my-blank-pvc
|
||||
labels:
|
||||
cdi.kubevirt.io/useStorageProfile: "true"
|
||||
cdi.kubevirt.io/applyStorageProfile: "true"
|
||||
spec:
|
||||
storageClassName: rook-ceph-block
|
||||
volumeMode: FromStorageProfile
|
||||
@ -57,7 +57,7 @@ kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: my-imported-pvc
|
||||
labels:
|
||||
cdi.kubevirt.io/useStorageProfile: "true"
|
||||
cdi.kubevirt.io/applyStorageProfile: "true"
|
||||
spec:
|
||||
dataSourceRef:
|
||||
apiGroup: cdi.kubevirt.io
|
||||
@ -76,7 +76,7 @@ kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: my-cloned-pvc
|
||||
labels:
|
||||
cdi.kubevirt.io/useStorageProfile: "true"
|
||||
cdi.kubevirt.io/applyStorageProfile: "true"
|
||||
spec:
|
||||
dataSourceRef:
|
||||
apiGroup: cdi.kubevirt.io
|
||||
|
@ -51,7 +51,7 @@ func (wh *pvcMutatingWebhook) Admit(ar admissionv1.AdmissionReview) *admissionv1
|
||||
}
|
||||
|
||||
// Note the webhook LabelSelector should not pass us such pvcs
|
||||
if pvc.Labels[common.PvcUseStorageProfileLabel] != "true" {
|
||||
if pvc.Labels[common.PvcApplyStorageProfileLabel] != "true" {
|
||||
klog.Warningf("Got PVC %s/%s which was not labeled for rendering", pvc.Namespace, pvc.Name)
|
||||
return allowedAdmissionResponse()
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ const (
|
||||
// DataImportCronCleanupLabel tells whether to delete the resource when its DataImportCron is deleted
|
||||
DataImportCronCleanupLabel = DataImportCronLabel + ".cleanup"
|
||||
|
||||
// PvcUseStorageProfileLabel tells whether the PVC should be rendered by the mutating webhook based on StorageProfiles
|
||||
PvcUseStorageProfileLabel = CDIComponentLabel + "/useStorageProfile"
|
||||
// PvcApplyStorageProfileLabel tells whether the PVC should be rendered by the mutating webhook based on StorageProfiles
|
||||
PvcApplyStorageProfileLabel = CDIComponentLabel + "/applyStorageProfile"
|
||||
|
||||
// ImporterVolumePath provides a constant for the directory where the PV is mounted.
|
||||
ImporterVolumePath = "/data"
|
||||
|
@ -1129,13 +1129,13 @@ func (r *ReconcilerBase) newPersistentVolumeClaim(dataVolume *cdiv1.DataVolume,
|
||||
}
|
||||
annotations[cc.AnnPreallocationRequested] = strconv.FormatBool(cc.GetPreallocation(context.TODO(), r.client, dataVolume.Spec.Preallocation))
|
||||
|
||||
if dataVolume.Spec.Storage != nil && labels[common.PvcUseStorageProfileLabel] == "true" {
|
||||
if dataVolume.Spec.Storage != nil && labels[common.PvcApplyStorageProfileLabel] == "true" {
|
||||
isWebhookPvcRenderingEnabled, err := featuregates.IsWebhookPvcRenderingEnabled(r.client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isWebhookPvcRenderingEnabled {
|
||||
labels[common.PvcUseStorageProfileLabel] = "true"
|
||||
labels[common.PvcApplyStorageProfileLabel] = "true"
|
||||
if targetPvcSpec.VolumeMode == nil {
|
||||
targetPvcSpec.VolumeMode = ptr.To[corev1.PersistentVolumeMode](cdiv1.PersistentVolumeFromStorageProfile)
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func pvcFromStorage(client client.Client, recorder record.EventRecorder, log log
|
||||
return nil, err
|
||||
}
|
||||
|
||||
shouldRender := !isWebhookRenderingEnabled || dv.Labels[common.PvcUseStorageProfileLabel] != "true"
|
||||
shouldRender := !isWebhookRenderingEnabled || dv.Labels[common.PvcApplyStorageProfileLabel] != "true"
|
||||
|
||||
if pvc == nil {
|
||||
pvcSpec = copyStorageAsPvc(log, dv.Spec.Storage)
|
||||
|
@ -458,7 +458,7 @@ func initPvcMutatingWebhook(whc *admissionregistrationv1.MutatingWebhookConfigur
|
||||
},
|
||||
ObjectSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
common.PvcUseStorageProfileLabel: "true",
|
||||
common.PvcApplyStorageProfileLabel: "true",
|
||||
},
|
||||
},
|
||||
ReinvocationPolicy: &reinvocationNever,
|
||||
|
@ -193,7 +193,7 @@ var _ = Describe("Clone Populator tests", func() {
|
||||
}
|
||||
pvc := generateTargetPVCWithStrategy(size, vm, strategy, scName)
|
||||
pvc.Spec.AccessModes = nil
|
||||
cc.AddLabel(pvc, common.PvcUseStorageProfileLabel, "true")
|
||||
cc.AddLabel(pvc, common.PvcApplyStorageProfileLabel, "true")
|
||||
err := f.CrClient.Create(context.Background(), pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
f.ForceSchedulingIfWaitForFirstConsumerPopulationPVC(pvc)
|
||||
|
@ -2115,7 +2115,7 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
|
||||
},
|
||||
}
|
||||
dataVolume := createLabeledDataVolumeForImport(f, spec,
|
||||
map[string]string{common.PvcUseStorageProfileLabel: webhookRenderingLabel})
|
||||
map[string]string{common.PvcApplyStorageProfileLabel: webhookRenderingLabel})
|
||||
|
||||
By("verifying pvc not created")
|
||||
_, err := utils.FindPVC(f.K8sClient, dataVolume.Namespace, dataVolume.Name)
|
||||
@ -2155,7 +2155,7 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
|
||||
},
|
||||
}
|
||||
dataVolume := createLabeledDataVolumeForImport(f, spec,
|
||||
map[string]string{common.PvcUseStorageProfileLabel: webhookRenderingLabel})
|
||||
map[string]string{common.PvcApplyStorageProfileLabel: webhookRenderingLabel})
|
||||
|
||||
By("verifying event occurred")
|
||||
Eventually(func() bool {
|
||||
@ -2204,7 +2204,7 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
|
||||
},
|
||||
}
|
||||
dataVolume := createLabeledDataVolumeForImport(f, spec,
|
||||
map[string]string{common.PvcUseStorageProfileLabel: webhookRenderingLabel})
|
||||
map[string]string{common.PvcApplyStorageProfileLabel: webhookRenderingLabel})
|
||||
|
||||
By("verifying pvc not created")
|
||||
_, err := utils.FindPVC(f.K8sClient, dataVolume.Namespace, dataVolume.Name)
|
||||
@ -2628,7 +2628,7 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
|
||||
By(fmt.Sprintf("creating new datavolume %s with StorageClassName %s", dataVolumeName, scName))
|
||||
dataVolume := utils.NewDataVolumeWithHTTPImportAndStorageSpec(
|
||||
dataVolumeName, "100Mi", fmt.Sprintf(utils.TinyCoreQcow2URL, f.CdiInstallNs))
|
||||
dataVolume.Labels = map[string]string{common.PvcUseStorageProfileLabel: webhookRenderingLabel}
|
||||
dataVolume.Labels = map[string]string{common.PvcApplyStorageProfileLabel: webhookRenderingLabel}
|
||||
dataVolume.Spec.Storage.StorageClassName = ptr.To[string](scName)
|
||||
dataVolume.Spec.Storage.AccessModes = nil
|
||||
|
||||
|
@ -1628,7 +1628,7 @@ var _ = Describe("Import populator", func() {
|
||||
|
||||
if webhookRendering {
|
||||
tests.EnableWebhookPvcRendering(f.CrClient)
|
||||
controller.AddLabel(pvc, common.PvcUseStorageProfileLabel, "true")
|
||||
controller.AddLabel(pvc, common.PvcApplyStorageProfileLabel, "true")
|
||||
// Unset AccessModes which will be set by the webhook rendering
|
||||
pvc.Spec.AccessModes = nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user